Skip to content

@types/react@18.2.8 + jsxImportSource: @emotion/react = Its return type 'ReactNode' is not a valid JSX element. #3049

@karlhorky

Description

@karlhorky

Current behavior:

Over the last months, there have been significant changes to the TypeScript @types/react package by @eps1lon in order to accommodate the different return types of components (one of the reasons being to avoid the problems with async React components)

Using "jsxImportSource": "@emotion/react" along with the new @types/react@18.2.8 package causes failures that look like this:

'Title' cannot be used as a JSX component.
  Its return type 'ReactNode' is not a valid JSX element.
    Type 'undefined' is not assignable to type 'Element | null'.

CodeSandbox: https://codesandbox.io/p/sandbox/emotion-issue-template-forked-vsng2b?file=%2Fsrc%2FApp.tsx

Screenshot 2023-06-04 at 16 30 12

To reproduce:

  1. Fork the sandbox reproduction: https://codesandbox.io/s/emotion-issue-template-y306ue
  2. Upgrade all versions of all dependencies and devDependencies
  3. TypeScript error appears

Expected behavior:

"jsxImportSource": "@emotion/react" and the @types/react@18.2.8 package are compatible

Environment information:

  • react version: 18.2.0
  • @emotion/react version: 11.11.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions