我正在使用流程类型,并具有一个备忘包装的功能组件,但是,当尝试为响应导航分配navigationOptions时,流程就很麻烦了。
在我的组件上
const navigationOptions = ({navigation}) => ({}) // more stuff const Foo = memo((props: IProps) => { ... }) /* Here it breaks down Cannot assign `navigationOptions` to `Foo['navigation...']` because property `navigationOptions` is missing in `React.AbstractComponentStatics` */ Foo.navigationOptions = navigationOptions export default Foo
即使我将其强制转换为任意类型,然后尝试在路由器上使用它:
/* Cannot call `createStackNavigator` with object literal bound to `routeConfigMap` because in property `Foo.screen`: Either property `navigationOptions` is missing in AbstractComponent [1] but exists in `withOptionalNavigationOptions` [2]. Or property `router` is missing in AbstractComponent [1] but exists in `withRouter` [3].Flow(InferError) */ const FooStack = createStackNavigator({ Foo: { screen: FooScreen } }, stackNavOptions)
我应该如何在此处正确应用类型?
我正在使用流类型,并具有一个备忘包装的功能组件,但是,当尝试为响应导航分配navigationOptions时,流只是在搞麻烦:在我的组件const ...
这是预期的行为。如果您实际检查React$AbstractComponentStatics
,您会看到几乎没有允许的属性,例如displayName
是有效的。他们甚至删除了propTypes,即使它是有效的也不鼓励使用,这就是为什么要删除它。