我在我的反应本机应用程序中使用带有反应导航库的打字稿。我按照官方文档中提供的指南对我的屏幕进行注释。
问题是我创建的类型有太多重复。有什么方法可以使这种类型动态化,我只需要提供屏幕名称,而不是一次又一次地定义所有类型。
这里是注释我的屏幕的代码,我想让这个“登陆”字符串相对于每个屏幕都是动态的。希望我说清楚了。
type LandingProps = CompositeScreenProps<
NativeStackScreenProps<HomeStackParamList, "landing">,
DrawerScreenProps<AppDrawerParamList>
>;
你可以...
type CPProps<T extends string> = CompositeScreenProps<
NativeStackScreenProps<HomeStackParamList, T>,
DrawerScreenProps<AppDrawerParamList>
>;
然后
type LandingProps = CPProps<"landing">;
NativeStackScreenProps
的第二个类型参数可能会受到进一步的约束。如果是这样,请更改
T extends string
要匹配它。