Reactjs 反应导航和打字脚本。财产';getScreen';类型中缺少
使用TypeScript和react导航可获得以下TypeScript问题:Reactjs 反应导航和打字脚本。财产';getScreen';类型中缺少,reactjs,typescript,react-navigation,Reactjs,Typescript,React Navigation,使用TypeScript和react导航可获得以下TypeScript问题: Property 'Principles' is incompatible with index signature. Type '{ screen: (props: any) => Element; path: string; }' is not assignable to type 'NavigationRouteConfig'. Type '{ screen: (props: any
Property 'Principles' is incompatible with index signature.
Type '{ screen: (props: any) => Element; path: string; }' is not assignable to type 'NavigationRouteConfig'.
Type '{ screen: (props: any) => Element; path: string; }' is not assignable to type '{ navigationOptions?: any; path?: string; } & { getScreen: () => NavigationComponent; }'.
Type '{ screen: (props: any) => Element; path: string; }' is not assignable to type '{ getScreen: () => NavigationComponent; }'.
Property 'getScreen' is missing in type '{ screen: (props: any) => Element; path: string; }'.
以下是“我的导航器”中的代码:
const MainNavigator: NavigationContainer = StackNavigator({
Principles: {
screen: props => <WebViewModal source={{ uri: MY_URI }} {...props} />,
path: 'principles',
},
})
如何解决此typescript问题?查看react导航的index.d.ts,我发现您可以执行以下操作:
Principles: {
getScreen: () => props => <WebViewModal source={{ uri: MY_URI }} {...props} />,
path: 'principles',
},
原则:{
getScreen:()=>道具=>,,
路径:"原则",,
},
然而,当我看到这个错误时,我也能够摆脱它,而不改变代码,只是简单地删除了node_模块和warn.lock,然后再次运行warn安装。我看到了同样的情况。真奇怪。
Principles: {
getScreen: () => props => <WebViewModal source={{ uri: MY_URI }} {...props} />,
path: 'principles',
},