react-color icon indicating copy to clipboard operation
react-color copied to clipboard

React 18 typescript problem

Open vocko opened this issue 3 years ago • 12 comments
trafficstars

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

vocko avatar Apr 12 '22 04:04 vocko

+1

kbzowski avatar Apr 12 '22 11:04 kbzowski

is there any progress?

tunjayhuseynov avatar Apr 25 '22 19:04 tunjayhuseynov

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?

reinos avatar May 09 '22 13:05 reinos

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.

Newton-Maurya avatar May 20 '22 07:05 Newton-Maurya

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

'ChromePicker' cannot be used as a JSX component.

Vesli avatar Jun 16 '22 12:06 Vesli

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 avatar Jun 29 '22 08:06 iulianraduat

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

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

iulianraduat avatar Jun 30 '22 12:06 iulianraduat

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"
     },

faran4hatch avatar Jul 25 '22 08:07 faran4hatch

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

alfonsograziano avatar Aug 17 '22 15:08 alfonsograziano

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

iamgabrielsoft avatar Oct 15 '22 01:10 iamgabrielsoft

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

vocko avatar Dec 07 '22 02:12 vocko

可行的解决方案是在 package.json 中添加以下设置并重新安装软件包:

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

对于仍然对此感到疑惑的任何人,添加分辨率后重新安装软件包是使其正常工作的关键。

Package.json(节选)

"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

it's work!!thanks

febrosy avatar Feb 06 '23 05:02 febrosy