不能将类型 children string Element; 分配给类型Props。 属性children的类型不兼容。 类型string Element缺少类型ReactElementany string JSXElementConstructorany中的以下属性 type props keyts2322import ApplicationModalimport ModalF
在声明Props接口时,将children的类型指定为React.ReactElement而不是React.ReactElement[]。这是因为children应该是一个单独的ReactElement而不是一个元素数组。将Props接口的定义更改为以下内容应该能解决问题:
interface Props {
children: React.ReactElement;
}
然后,在函数组件的类型注解中将Props更改为React.PropsWithChildren<Props>:
const ApplicationModal: React.FC<React.PropsWithChildren<Props>> = (props) => {
// ...
};
这样应该可以解决类型错误。
原文地址: https://www.cveoy.top/t/topic/irHk 著作权归作者所有。请勿转载和采集!