我正在尝试访问 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 发出了警告。为什么?