简体   繁体   English

如何将 object 的数组传递给组件,类型 x 不可分配给类型“IntrinsicAttributes & x”

[英]how to pass array of object into component, Type x is not assignable to type 'IntrinsicAttributes & x'

array type looks like MyType: {name: string, age: number}[] , props type in component is the same数组类型看起来像MyType: {name: string, age: number}[] ,组件中的道具类型相同

<Content data={arrOfObj} /> // warning

const Content: React.FC<MyType> = (data) => {...}

how to pass it into component correctly?如何正确地将其传递给组件? and I also think in the component prop type actually is not equal to MyType.而且我也认为组件中的道具类型实际上不等于MyType。 To get access to data you need to write the following data.data , but because of ts thinks data is an array, you can`t write in this way要访问数据,您需要编写以下data.data ,但是由于 ts 认为 data 是一个数组,所以不能这样写

This is probably what you wanted这可能是你想要的

<Content data={arrOfObj} /> // warning

const Content: React.FC<{ data: MyType }> = ({ data }) => {...}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TS 皮棉错误; 类型 X 不可分配给类型 'IntrinsicAttributes &amp; RefAttributes<any> '</any> - TS Lint Error; Type X is not assignable to type 'IntrinsicAttributes & RefAttributes<any>' TypeScript - 类型“x”不可分配给类型“IntrinsicAttributes &amp; IntrinsicClassAttributes”<Class> &#39; - TypeScript - Type 'x' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Class>' 类型“{}”不可分配给类型“IntrinsicAttributes &amp; {}” - Type '{ }' is not assignable to type 'IntrinsicAttributes & {}' 类型不可分配给类型 IntrinsicAttributes - Type is not assignable to type IntrinsicAttributes 类型“{}”不可分配给类型“IntrinsicAttributes” - Type '{}' is not assignable to type 'IntrinsicAttributes' React Typescript:类型“X”不可分配给类型“IntrinsicAttributes &amp; {properties}”。 TS2322 - React Typescript: Type 'X' is not assignable to type 'IntrinsicAttributes & { properties }. TS2322 类型 ref 不可分配给类型 IntrinsicAttributes - Type ref is not assignable to type IntrinsicAttributes 类型“{}”不可分配给类型“IntrinsicAttributes &amp; IntrinsicClassAttributes” - Type '{}' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes 如何使用包含动作的组件? 获取错误“类型&#39;{}&#39;不能分配给&#39;IntrinsicAttributes&#39;类型 - How to use component which contains actions? Getting error “Type '{}' is not assignable to type 'IntrinsicAttributes” 不可分配给动态渲染组件的类型“IntrinsicAttributes &amp; ContentOutlineProps &amp; ContentBrainstormProps” - not assignable to type 'IntrinsicAttributes & ContentOutlineProps & ContentBrainstormProps' for dynamically rendered component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM