我不明白 TypeScript Drawer 组件缺少什么

发布于 2025-01-11 18:17:37 字数 1103 浏览 0 评论 0原文

我是 TypeScript 的新手,在继续构建应用程序的过程中一直在努力学习。

我在 VSCode 中看到的错误是:

Type '{ state: DrawerNavigationState;导航:DrawerNavigationHelpers;描述符:DrawerDescriptorMap; }' 与类型 'IntrinsicAttributes'.ts(2559) 没有共同的属性

此错误出现在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遗心遗梦遗幸福 2025-01-18 18:17:38

您将 {...props} 传递给 CustomDrawerContent,但它不接受代码中的任何 props (const CustomDrawerContent = () => { )。

我为此创建的类型是 RootDrawerParamList。这是:

这是不相关的,但也是不正确的。您需要为屏幕接受的任何参数指定类型,但您已经为屏幕的 props 指定了类型。 params 和 props 不是一回事。

You're passing {...props} to CustomDrawerContent but it doesn't accept any props in your code (const CustomDrawerContent = () => {).

The type I created for this was RootDrawerParamList. Which is:

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.

只想待在家 2025-01-18 18:17:38

您使用的是哪个版本的反应导航。

我正在使用的版本中的类型定义是:

export function createDrawerNavigator(
  routeConfigMap: NavigationRouteConfigMap,
  drawerConfig?: DrawerNavigatorConfig
): NavigationContainer;

Which version of react-navigation are you using.

The type definition in the version I am using is:

export function createDrawerNavigator(
  routeConfigMap: NavigationRouteConfigMap,
  drawerConfig?: DrawerNavigatorConfig
): NavigationContainer;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文