我有带有 Typescript 和 React 环境的标准箭头映射 ES7 函数:
const getItemList: Function = (groups: any[]): JSX.Element =>
group.map((item: any, i: number) => {
const itemCardElemProps = { handleEvents: () => {}, ...item}
return <Item key={`${item.id}_${i}`} {...itemCardElemProps} />
})
并得到错误:
TS2739: Type 'Element[]' is missing the following properties from type 'Element': type, props, key
版本:打字稿3.5.3
原文由 Roman 发布,翻译遵循 CC BY-SA 4.0 许可协议
您也可以始终将单个 JSX.Element 作为片段发回:
这样您就可以匹配返回的类型,并且不会影响您的标记。