interface FatherProps {
data?: string[];
}
interface SonProps {
data: string[];
}
const Father: React.FC<FatherProps> = (props) => {
return (
<Son data={props.data as string[]}></Son>
)
}
const Son: React.FC<SonProps> = (props) => {
return (
<div>son son son</div>
)
}
除了使用as
外还有其它好用的方法么?
看到其它组件源码这种可选参数 是直接使用的
知道了问题所在了,

源码中有个默认值操作,那么解决问题应该就只有两个了
as
再添加一种方式,修改
tsconfig.json
配置关闭严格空值检查即可,react component 组件源码中也是如此处理的