You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Type error when using ReactModal as a JSX component.
Steps to reproduce:
Import ReactModal from react-modal.
Use ReactModal in a JSX component.
Compile the code.
Expected behavior:
The ReactModal component should render without type errors.
Additional notes:
This is the TypeScript error message:
'ReactModal' cannot be used as a JSX component.
Its type 'typeof ReactModal' is not a valid JSX element type.
Type 'typeof ReactModal' is not assignable to type 'new (props: any) => Component<any, any, any>'.
Construct signature return types 'ReactModal' and 'Component<any, any, any>' are incompatible.
The types returned by 'render()' are incompatible between these types.
Type 'import("/Users/nodirbekrajaboff/Desktop/projects/digital-aggregator/node_modules/@types/react-modal/node_modules/@types/react/index").ReactNode' is not assignable to type 'React.ReactNode'.
Type 'ReactElement<any, string | JSXElementConstructor<any>>' is not assignable to type 'ReactNode'.
Property 'children' is missing in type 'ReactElement<any, string | JSXElementConstructor<any>>' but required in type 'ReactPortal'.ts(2786)
Additional TypeScript error messages:
Type 'ReactElement<any, string | JSXElementConstructor<any>>' is not assignable to type 'ReactNode'.
Property 'children' is missing in type 'ReactElement<any, string | JSXElementConstructor<any>>' but required in type 'ReactPortal'.ts(2322)
index.d.ts(387, 9): 'children' is declared here.
index.d.ts(2156, 9): The expected type comes from property 'children' which is declared here on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'
For: {contentElement}
No overload matches this call.
Overload 1 of 2, '(props: Props): ReactModal', gave the following error.
Type 'React.ReactNode' is not assignable to type 'import("/Users/nodirbekrajaboff/Desktop/projects/digital-aggregator/node_modules/@types/react-modal/node_modules/@types/react/index").ReactNode'.
Type 'bigint' is not assignable to type 'ReactNode'.
Overload 2 of 2, '(props: Props, context: any): ReactModal', gave the following error.
Type 'React.ReactNode' is not assignable to type 'import("/Users/nodirbekrajaboff/Desktop/projects/digital-aggregator/node_modules/@types/react-modal/node_modules/@types/react/index").ReactNode'.
Type 'bigint' is not assignable to type 'ReactNode'.ts(2769)
index.d.ts(41, 9): The expected type comes from property 'children' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<ReactModal> & Readonly<Props>'
index.d.ts(41, 9): The expected type comes from property 'children' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<ReactModal> & Readonly<Props>'
I think the issue is that your @types/react-modal installation has its own copy of @types/react at a different major version from the rest of your project. One clue is the import path in this line of the error:
Type 'import("/Users/nodirbekrajaboff/Desktop/projects/digital-aggregator/node_modules/@types/react-modal/node_modules/@types/react/index").ReactNode' is not assignable to type 'React.ReactNode'.
node_modules/@types/react-modal/node_modules/@types/react points at the incompatible copy of the React types, while the React.ReactNode type at the end of that message is presumably under node_modules/@types/react.
DefinitelyTyped/DefinitelyTyped#59765 (comment) is the most helpful comment I've seen to explain why this happens and suggest possible fixes for Yarn users: adding a "resolutions" entry in package.json, or cleaning up your yarn.lock and reinstalling.
(I'm not sure if you're actually using Yarn, but it's the only package manager I've seen mentioned in similar GitHub issues, and I couldn't reproduce this when I did a React 18 -> 19 upgrade with npm. To be clear, Yarn's behavior is correct given how @types/react-modal defines that dependency so loosely in its package.json. I'm not sure if there's a reason it was set up that way instead of as a peer dependency.)
With React v19
Summary:
Type error when using
ReactModal
as a JSX component.Steps to reproduce:
ReactModal
fromreact-modal
.ReactModal
in a JSX component.Expected behavior:
The
ReactModal
component should render without type errors.Additional notes:
This is the TypeScript error message:
Additional TypeScript error messages:
For:
{contentElement}
For:
{children}
Codes:
The text was updated successfully, but these errors were encountered: