Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React 18 typescript problem #855

Open
vocko opened this issue Apr 12, 2022 · 12 comments
Open

React 18 typescript problem #855

vocko opened this issue Apr 12, 2022 · 12 comments

Comments

@vocko
Copy link

vocko commented Apr 12, 2022

React has tightened it¤s typing restrictions in v18 and as a result there are a several typescript errors in the project:

 TS2786: 'Saturation' cannot be used as a JSX component.
<e>   Its instance type 'Saturation' is not a valid JSX element.
<e>     The types returned by 'render()' are incompatible between these types.
<e>       Type 'import("/node_modules/@types/react-dom/node_modules/@types/react/index").ReactNode' is not assignable to type 'React.ReactNode'.
<e> TS2786: 'Hue' cannot be used as a JSX component.
<e>   Its instance type 'Hue' is not a valid JSX element.
<e>     The types returned by 'render()' are incompatible between these types.
<e>       Type 'import("/node_modules/@types/react-dom/node_modules/@types/react/index").ReactNode' is not assignable to type 'React.ReactNode'.
@kbzowski
Copy link

+1

@tunjayhuseynov
Copy link

is there any progress?

@reinos
Copy link

reinos commented May 9, 2022

I think changing the dependency to react 18 in https://github.com/casesandberg/react-color/blob/master/package.json#L90 will fix this issue.

Can someone confirm if that is working?

@Newton-Maurya
Copy link

I think changing the dependency to react 18 in https://github.com/casesandberg/react-color/blob/master/package.json#L90 will fix this issue.

Can someone confirm if that is working?

No, it's not working.

@Vesli
Copy link

Vesli commented Jun 16, 2022

it would be really nice to have this fixed, I have the same with

'ChromePicker' cannot be used as a JSX component.

@iulianraduat
Copy link

iulianraduat commented Jun 29, 2022

The same with SketchPicker so it looks like all exported sub-components are affected 😭

The working solution: add in package.json

  "resolutions": {
    "@types/react": "^18.0.0"
  },

@iulianraduat
Copy link

The working solution is to add in package.json the bellow setting and re-install the packages:

  "resolutions": {
    "@types/react": "^18.0.0"
  },

@faran4hatch
Copy link

Still getting this error for SketchPicker

Its instance type 'SketchPicker' is not a valid JSX element.
    The types returned by 'render()' are incompatible between these types.
      Type 'import("/Users/faran/Documents/code/node_modules/@types/react/index").ReactNode' is not assignable to type 'React.ReactNode'.
        Type '{}' is not assignable to type 'ReactNode'.

        <SketchPicker
        ~~~~~~~~~~~~

I have the following in package.json

    "react": "^18.2.0",
    "react-color": "2.19.3",
    "react-dom": "^18.2.0",

    "resolutions": {
        "@types/react": "^18.0.15",
        "@types/react-dom": "^18.0.6"
     },

@alfonsograziano
Copy link

Same error for me... Does someone have a working solution?

@iamgabrielsoft
Copy link

iamgabrielsoft commented Oct 15, 2022

i had to edit my answer here, @iulian-radu-at solution worked for me

@vocko
Copy link
Author

vocko commented Dec 7, 2022

The working solution is to add in package.json the bellow setting and re-install the packages:

  "resolutions": {
    "@types/react": "^18.0.0"
  },

For anyone still wondering about this one, RE-INSTALL the packages after adding the resolutions is the key to get this working.

Package.json (excerpt)

"resolutions": {
  "@types/react": "^18.0.26",
  "@types/react-dom": "^18.0.9"
},
yarn remove react-color @types/react-color
yarn add react-color-@types/react-color

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

11 participants