首页 > 解决方案 > 类型“ConnectedComponentClass<>”不可分配给类型“ComponentType”

问题描述

因此,我在带有 typescript 和 redux 的 react-native 项目中使用 react-navigation,但是当我为抽屉导航器设置 contentComponent 道具时,我在 typescript 中收到此错误。

键入'ConnectedComponentClass<SomeClass>' is not assignable to type 'ComponentType<DrawerItemsProps>' Type 'SomeClass' is missing the following properties from type 'DrawerItemsProps': navigation, items, getLabel, renderIcon, and 2 more.

是否有相同的解决方法。

对此的任何帮助将不胜感激。

标签: typescriptreact-nativereact-navigationreact-navigation-drawer

解决方案


It seems that the type DrawerItemsProps has properties like navigation, items, getLabel, renderIcon and more and these are missing in your SomeClass interface.

So you can make all these properties which are missing as optional using '?' like below

interface DrawerItemsProps {
  // other properties
  navigation?: yourType,
  items?: yourType, 
  getLabel?: yourType,
  renderIcon?: yourType
}

推荐阅读