【发布时间】:2020-05-13 21:48:41
【问题描述】:
我开始在我的 react native 项目(typescript 新手)中使用 typescript,并在使用 typescript 的功能组件中遇到了 navigationOptions 问题,感谢这篇文章 here 我解决了这个问题,但是当我尝试传递 redux 道具时它告诉我
Property 'authType' does not exist on type 'PropsWithChildren<NavigationStackScreenProps<Params, Props>>
这是我的代码
interface Props {
authType: string;
}
interface Params {
routeName: string;
}
const Customer: NavigationStackScreenComponent<Params, Props> = ({
navigation,
authType,
}) => {
.... Component
}
Customer.navigationOptions = ({ navigation }) => ({
title: navigation.getParam('routeName'),
});
我认为这意味着我正在传递的道具没有被读取,尽管我正在传递它。
我使用 NavigationStackScreenComponent 是为了能够使用
Customer.navigationOptions etc
否则它会告诉我
ts] Property 'navigationOptions' does not exist
我真的开始爱上打字稿了,知道如何使用 authType Props 而不会让我尖叫吗?
【问题讨论】:
标签: typescript react-native react-navigation react-navigation-stack