【发布时间】:2020-03-08 03:09:48
【问题描述】:
我正在尝试在我的应用程序中访问 React [Native] 组件的 props(保证是我的自定义类型 ItemTemplate 的元素的实例:
const children = React.Children.toArray(this.props.children);
return children.find(t => t.props.itemKey == key);
但是,当我尝试访问 t.props 时,在第二行中我得到:
Property 'props' does not exist on type 'ReactElement<ItemTemplate, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)> | ... 13 more ... | (ReactElement<...>[] & ReactPortal)'.
Property 'props' does not exist on type 'ReactElement<ItemTemplate, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)>[] & string'.
代码工作正常,但 TypeScript (3.6.3) IntelliSense 出现问题。 为什么?
【问题讨论】:
-
投反对票的人至少可以解释原因吗?
标签: reactjs typescript react-native react-props typescript-types