我有一个类似的反应成分
const Example = () => (<View>...</View>);
使用react-navigation我通常会通过说来应用导航选项
Example.navigationOptions = { options };
使用打字稿我得到了错误
[ts] Property 'navigationOptions' does not exist on type '(props: Props) => Element'.
我怎样才能解决这个问题?
我尝试编写一个界面
interface ExampleWithNavigationOptions extends Element { navigationOptions?; }
但是没有运气。
关键思想是为Example常量指定正确的类型。可能react-navigation已经提供了该类型。但是,您也可以这样扩展内置React接口:
Example
react-navigation
React
interface NavStatelessComponent extends React.StatelessComponent { navigationOptions?: Object } const Example: NavStatelessComponent = () => { return ( <View> ... </View> ) } Example.navigationOptions = { /* ... */ } Example.propTypes = { /* ... */ }