我在.tsx文件中使用React.memo()(React typescript)
现在,我将Props的接口声明为:
interface Props {
type?: string;
}
Run Code Online (Sandbox Code Playgroud)
我的组件看起来像:
const Component: React.SFC<Props> = props => {
/// return something;
};
export default memo(Component);
Run Code Online (Sandbox Code Playgroud)
现在,由于type是一个可选的道具,我打算仅在某些时候使用它。
如果我使用我的组件,<Component type="something" />一切都很好。但是如果我在<Component />收到错误时使用它->
输入'{children:string; }”与“ IntrinsicAttributes&Props”类型没有共同的属性。
这似乎是一个非常荒谬的错误,因为我已经在Code沙箱上尝试过此方法,并且一切正常。关于错误可能是什么的任何想法?
更新
如果我在接口中明确添加道具
interface Props {
type?: string;
children?: ReactNode;
}
Run Code Online (Sandbox Code Playgroud)
那么在这种情况下,一切都很好。这应该是隐式的,但要考虑到它的错误
'{儿童:字符串;}'
有任何想法吗???