简体   繁体   English

React Antd 模态属性 'children' 在类型'IntrinsicAttributes & ModalProps' 上不存在

[英]React Antd Modal Property 'children' does not exist on type 'IntrinsicAttributes & ModalProps'

After upgrading to React 18 I have the following issue with Antd.升级到 React 18 后,我遇到了 Antd 的以下问题。

When using a component from Antd (Modal, Dialog, ...) it gives me this error:当使用来自 Antd 的组件(模态,对话框,...)时,它给了我这个错误:

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'.

Here is my component:这是我的组件:

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>

  );
}

And here my Props:这里是我的道具:

type Props = {
  children: React.ReactNode,
  open: boolean,
  onClose?: () => void
}

I use node 17.8.0我使用节点 17.8.0

you should use你应该使用

"@types/react": "17.0.39" 

instead of代替

"@types/react": "18.0.3"

because react18 @types is not yet compatible.因为 react18 @types 还不兼容。

Issue is related to latest updates of types in react 18. In order to avoid this error if you use yarn one solution would be be to use resolutions in package.json with some lower version of react.问题与 react 18 中类型的最新更新有关。如果您使用 yarn,为了避免此错误,一种解决方案是使用 package.json 中的分辨率和一些较低版本的 react。 This way your dependency will be instructed to use types form diff version.这样,您的依赖项将被指示使用不同版本的类型。

Example:例子:

"resolutions": { "@types/react": "17.0.30" }

I prefer using this comment to ignore TS error instead of downgrading types我更喜欢使用此注释来忽略 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>
  );
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React:如何解决:“IntrinsicAttributes & Props”类型上不存在属性“children” - React: How to solve: Property 'children' does not exist on type 'IntrinsicAttributes & Props' 属性不存在于类型 'IntrinsicAttributes & { children?: ReactNode; }' - Property does not exist on type 'IntrinsicAttributes & { children?: ReactNode; }' “IntrinsicAttributes”类型上不存在模态属性“show” - Modal Property 'show' does not exist on type 'IntrinsicAttributes' React forwardRef - 类型 IntrinsicAttributes 上不存在属性 - React forwardRef - Property does not exist on type IntrinsicAttributes React-类型IntrinsicAttributes上不存在属性 - React - Property does not exist on type IntrinsicAttributes 类型'IntrinsicAttributes &amp; PhoneInputProps &amp; { children?: ReactNode; 上不存在属性'ref' } - Property 'ref' does not exist on type 'IntrinsicAttributes & PhoneInputProps & { children?: ReactNode; } 重构对Typecript的反应会导致错误属性&#39;readOnly&#39;在类型&#39;IntrinsicAttributes&InputProps&{children?:ReactNode; }” - Refactoring React to Typescript causes error Property 'readOnly' does not exist on type 'IntrinsicAttributes & InputProps & { children?: ReactNode; }' React 中的 MsalAuthProvider 错误:“IntrinsicAttributes 和 IAzureADProps”类型上不存在“孩子” - MsalAuthProvider in React error : 'children' does not exist on type 'IntrinsicAttributes & IAzureADProps' &#39;IntrinsicAttributes &amp; IntrinsicClassAttributes 类型上不存在属性<DatePicker> &amp; Readonly&lt;{ children?: ReactNode; }&gt; ...&#39; - Property does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<DatePicker> & Readonly<{ children?: ReactNode; }> …' 类型“IntrinsicAttributes &amp; ThirdwebWeb3ProviderProps”上不存在属性“children” - Property 'children' does not exist on type 'IntrinsicAttributes & ThirdwebWeb3ProviderProps'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM