TS2786: 'X' cannot be used as a JSX component (TypeScript) — how to fix
error TS2786: 'Header' cannot be used as a JSX component.
Its return type 'Element | undefined' is not a valid JSX element.
Type 'undefined' is not assignable to type 'Element | null'.
error TS2786: 'Page' cannot be used as a JSX component.
Its return type 'Promise<Element>' is not a valid JSX element.
Quick fix: Make every code path return JSX or null (not undefined). If the message mentions two React types that look identical, dedupe @types/react: npm ls @types/react, then pin one version via overrides (npm) or resolutions (yarn). For async server components, upgrade TypeScript and @types/react.
What it means
When you write <Header />, TypeScript checks that Header is a function or class whose return type is a valid JSX element (roughly ReactNode-compatible for newer setups, JSX.Element | null for older ones). If the return type, or the type of the component itself, doesn't fit, you get TS2786. Read the second line of the message: it says which part failed.
Cause 1: a code path returns undefined
function Header({ user }: { user?: User }) {
if (!user) return; // returns undefined
return <h1>{user.name}</h1>;
}
Return null to render nothing:
if (!user) return null;
Also check for a missing return in a .map() callback written with braces, or a function that ends without returning.
Cause 2: two versions of @types/react
Messages like "Type 'React.ReactNode' is not assignable to type 'React.ReactNode'" or "Type 'bigint' is not assignable to type 'ReactNode'" mean two copies of the React types are installed (for example one pulled in by a component library) and they disagree.
npm ls @types/react
Force a single version in package.json:
{
"overrides": {
"@types/react": "^18.3.0",
"@types/react-dom": "^18.3.0"
}
}
Yarn uses "resolutions" with the same shape; pnpm uses "pnpm": { "overrides": { ... } }. Then reinstall (rm -rf node_modules package-lock.json && npm install). Keep @types/react on the same major version as react.
Cause 3: async server components
export default async function Page() {
const data = await getData();
return <main>{data.title}</main>;
}
Older TypeScript/@types/react only allow components that return an element synchronously, so Promise<Element> fails. TypeScript 5.1 changed how JSX element types are checked so that libraries can allow this; update both:
npm install -D typescript@latest @types/react@latest @types/react-dom@latest
In VS Code, make sure the editor uses the workspace TypeScript version ("TypeScript: Select TypeScript Version").
Cause 4: the import is not a component
Importing an object or module namespace instead of the component (wrong default vs named import) gives TS2786 or TS2604. Check the export:
import { Header } from "./Header"; // if Header.tsx uses `export function Header`
import Header from "./Header"; // if it uses `export default`
Cause 5: class component typing from a library
Libraries built against old React types can declare class components that no longer match. Update the library, or as a temporary workaround wrap it:
const SafeChart = Chart as unknown as React.FC<ChartProps>;
Last updated 2026-12-01.