question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React 18 typescript problem

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:25
  • Comments:11

github_iconTop GitHub Comments

4reactions
iulian-radu-atcommented, Jun 30, 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"
  },
1reaction
vockocommented, 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
Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug: React 18 types broken since the type release a ... - GitHub
I want to reiterate that using TypeScript is a choice. You don't have to use React with TypeScript. If you choose to use...
Read more >
How to use TypeScript with React 18 alpha - LogRocket Blog
This is the TypeScript compiler complaining that it doesn't know anything about ReactDOM.createRoot . This is because the type definitions that ...
Read more >
Upgrading to react@18 and react-dom@18 fails
So, I went back and created a brand new app with npx create-react-app react18 --template typescript . It now wants react@18 and react-dom@18...
Read more >
React sur Twitter : "The React 18 TypeScript typings are out ...
There is an automated migration script that you can use to update your application code. It helps fix the most common issues when...
Read more >
Strict Mode - React
To help surface these issues, React 18 introduces a new development-only check to Strict Mode. This new check will automatically unmount and remount...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found