ui: Types not compatible with latest version of @types/react
I assume that this is mostly related to radix, but makes shadcn fail as well. Apparently the latest version @types/react has changed regarding ReactNode / children definition.
Here an example, looks like most components are affected though,
Versions used:
@types/react: 18.2.24"@radix-ui/react-slot": "^1.0.2"
TypeScript complains about the following eg. in ui/button.tsx:
Type 'React.ReactNode' is not assignable to type 'import("xxx/node_modules/@radix-ui/react-avatar/node_modules/@types/react/index").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'.
and
Type 'import("xxx/node_modules/@radix-ui/react-avatar/node_modules/@types/react/index").ReactNode' is not assignable to type 'React.ReactNode'
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 17
- Comments: 18
It turned out that the problem (at least with the current version of
@types/react18.2.31) was only related tobun. Removingnode_modules&bun.lockband then reinstalling all dependenciesbun installfixed it.As I am not so familiar with bun yet, I didn’t dive any deeper into the lockfile topic.
@shadcn sorry for the confusion.
Still having this issue with:
For anybody looking for a quick solution, downgrading to
"@types/react": "18.2.23"solved the problem for meIn my situation I needed to upgrade
@types/reactfrom19.0.10→19.0.12(if you’re using turborepo/monorepo setup, ensure that all packages are on that version)Still having this issue with
"react": "^19.1.0"and"@types/react": "^19.1.4",I think this is related to https://github.com/oven-sh/bun/issues/6103 - I see this occasionally, and a clean install would sometimes fix it, but the type mismatch — basically for me: is children required or not on ReactNode — keeps reoccuring.
oh, interesting, I even had to downgrade to
18.2.22seconded - was banging my head on this for a minute 🙏
you saved my life mate
I’m using Next.js 13 and extending @tsconfig/next/tsconfig.json, I simply removed @types/react from my project and it resolved the issues.
@mdugue just look in the package.json / pnpm lock: ‘@types/react’: specifier: ^18.2.7 version: 18.2.7