首页 > 解决方案 > ReactJS/Typescript 升级将 Child 的类型从 any 更改为 ReactNode

问题描述

最近尝试从 TypeScript 2.3(我知道)更新到 3.3 并遇到了 ReactJS 的问题,特别是 props.children 的类型。

this.props.children.map((s)=>{return <span>{s.prop1} - {s.prop2}</span>}); 

它曾经只是花花公子,但现在“孩子”是 ReactNode 类型而不是任何类型。这会导致编译器在“ReactNode”类型上不存在“map”时阻塞。

你们中的任何人都可以指出我克服这个障碍的方向吗?

标签: reactjstypescriptchildren

解决方案


推荐阅读