我不明白 TypeScript Drawer 组件缺少什么
我是 TypeScript 的新手,在继续构建应用程序的过程中一直在努力学习。
我在 VSCode 中看到的错误是:
Type '{ state: DrawerNavigationState
此错误出现在 CustomDrawerContent
我的代码当前实现的方式是:
const Drawer = createDrawerNavigator<RootDrawerParamList>();
const CustomDrawerContent = () => {
return (
<SafeAreaView>
<Text>Hellow</Text>
</SafeAreaView>
);
};
const DrawerNavigation = () => {
return (
<Drawer.Navigator
drawerContent={(props) => <CustomDrawerContent {...props} />}
>
<Drawer.Screen name="RootDrawer" component={LandingStackNavigation} />
</Drawer.Navigator>
);
};
export default DrawerNavigation;
我为此创建的类型是 <代码>RootDrawerParamList。哪一个是:
export type RootDrawerParamList = {
RootDrawer: DrawerScreenProps<LandingStackParamList>;
};
我对此缺少什么?感谢您帮助我了解应该如何处理此类错误
I am new to TypeScript and have been trying to learn as I continue to build an application.
The error I am seeing within VSCode is:
Type '{ state: DrawerNavigationState<ParamListBase>; navigation: DrawerNavigationHelpers; descriptors: DrawerDescriptorMap; }' has no properties in common with type 'IntrinsicAttributes'.ts(2559)
This error appears from CustomDrawerContent
The way my code is currently implemented is:
const Drawer = createDrawerNavigator<RootDrawerParamList>();
const CustomDrawerContent = () => {
return (
<SafeAreaView>
<Text>Hellow</Text>
</SafeAreaView>
);
};
const DrawerNavigation = () => {
return (
<Drawer.Navigator
drawerContent={(props) => <CustomDrawerContent {...props} />}
>
<Drawer.Screen name="RootDrawer" component={LandingStackNavigation} />
</Drawer.Navigator>
);
};
export default DrawerNavigation;
The type I created for this was RootDrawerParamList
. Which is:
export type RootDrawerParamList = {
RootDrawer: DrawerScreenProps<LandingStackParamList>;
};
What am I missing about this one? Thank you for helping me understanding how I should approach this type of error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将
{...props}
传递给CustomDrawerContent
,但它不接受代码中的任何 props (const CustomDrawerContent = () => { )。
这是不相关的,但也是不正确的。您需要为屏幕接受的任何参数指定类型,但您已经为屏幕的 props 指定了类型。 params 和 props 不是一回事。
You're passing
{...props}
toCustomDrawerContent
but it doesn't accept any props in your code (const CustomDrawerContent = () => {
).That's unrelated but that's also incorrect. You need to specify types for any params you accept for the screen, but you have specified types for props for the screen. Params and props aren't the same thing.
您使用的是哪个版本的反应导航。
我正在使用的版本中的类型定义是:
Which version of react-navigation are you using.
The type definition in the version I am using is: