【发布时间】:2020-07-09 22:04:24
【问题描述】:
我正在使用this guide 创建自定义抽屉内容:
const DrawerContent = (props) => (
<DrawerContentScrollView {...props}>
<AntDesign
name="close"
size={32}
onPress={() => props.navigation.closeDrawer()}
/>
<Text>TEST</Text>
<DrawerItemList {...props} />
</DrawerContentScrollView>
);
效果很好,但我想对props 参数进行类型检查。所以我尝试了:
import { DrawerContentComponentProps } from '@react-navigation/drawer';
const DrawerContent = (props: DrawerContentComponentProps) => (
// Same stuff
);
但我的 IDE 现在告诉我 props.navigation.closeDrawer 不存在,但确实存在。
定义DrawerContent函数的props类型的正确方法是什么?
【问题讨论】:
-
上面的代码很适合我。请澄清“我的 IDE 现在告诉我”是什么意思?确切的错误信息是什么?报告哪一行包含错误?在我看来,这是 调用
DrawerContent使用不完整参数的东西。 -
“NavigationHelpers
, DrawerNavigationEventMap>”类型上不存在属性“closeDrawer”。ts(2339)
标签: reactjs typescript react-native react-navigation