bbr*_*nck 5 typescript reactjs antd
升级到 React 18 后,我遇到了以下 Antd 问题。
\n当使用 Antd 中的组件(模态、对话框等)时,出现以下错误:
\nTS2322: 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'. \xc2\xa0\xc2\xa0Property 'children' does not exist on type 'IntrinsicAttributes & ModalProps'.\nRun Code Online (Sandbox Code Playgroud)\n这是我的组件:
\nfunction TransitionsModal(props: Props): JSX.Element {\n const {\n open,\n onClose,\n children\n } = props;\n\n return (\n <div>\n {open &&\n <Modal\n className="flex items-center justify-center"\n visible={open}\n onCancel={onClose}\n onOk={undefined}\n footer={null}\n closable={false}>\n {children}\n </Modal>\n }\n </div>\n\n );\n}\nRun Code Online (Sandbox Code Playgroud)\n这是我的道具:
\ntype Props = {\n children: React.ReactNode,\n open: boolean,\n onClose?: () => void\n}\nRun Code Online (Sandbox Code Playgroud)\n我使用节点17.8.0
\n小智 14
你应该使用
"@types/react": "17.0.39"
Run Code Online (Sandbox Code Playgroud)
代替
"@types/react": "18.0.3"
Run Code Online (Sandbox Code Playgroud)
因为react18 @types 还不兼容。