升级到Reactive18之后,我对Antd有以下问题。
使用Antd中的组件时(Modal,Dialog,.)它给了我这个错误:
TS2322: Type '{ children: ReactNode; ref: ForwardedRef<unknown>; className: string; visible: true; onCancel: (() => void) | undefined; onOk: undefined; footer: null; closable: false; }' is not assignable to type 'IntrinsicAttributes & ModalProps'. Property 'children' does not exist on type 'IntrinsicAttributes & ModalProps'.
这是我的组成部分:
function TransitionsModal(props: Props): JSX.Element {
const {
open,
onClose,
children
} = props;
return (
<div>
{open &&
<Modal
className="flex items-center justify-center"
visible={open}
onCancel={onClose}
onOk={undefined}
footer={null}
closable={false}>
{children}
</Modal>
}
</div>
);
}
我的道具:
type Props = {
children: React.ReactNode,
open: boolean,
onClose?: () => void
}
我使用节点17.8.0
发布于 2022-04-15 03:10:23
你应该使用
"@types/react": "17.0.39"
而不是
"@types/react": "18.0.3"
因为react18 @类型还不兼容。
发布于 2022-04-15 13:08:32
问题与react 18中类型的最新更新有关。为了避免这一错误,如果您使用纱线,一种解决方案是在package.json中使用分辨率较低的react。通过这种方式,将指示您的依赖项使用类型form diff版本。
示例:
"resolutions": { "@types/react": "17.0.30" }
发布于 2022-06-03 12:57:14
我更喜欢使用这个注释来忽略TS错误,而不是降级类型。
const MasonryBrick: FC<PostCardType> = ({ imgSrc, title, excerpt }) => {
return (
// @ts-ignore this lib is incompatible with react18
<Slide triggerOnce direction="up">
<div className={s.context}>
<h2>{title}</h2>
<p>{excerpt}</p>
</div>
</Slide>
);
};
https://stackoverflow.com/questions/71856714
复制相似问题