JSX Types
JSX types are how TypeScript checks <Foo /> syntax. The jsx compiler option picks the emit, and the JSX namespace (usually from @types/react) maps tag names to prop types.
Detailed Explanation
A .tsx file can contain JSX. TypeScript parses it and then asks the JSX namespace what a tag means. That namespace is not built into the compiler as React. It is filled by a types package.
compilerOptions.jsx controls emit: react (React.createElement), react-jsx (the automatic runtime), preserve, react-native. It does not, by itself, load React types. You still install @types/react (or React's bundled types) and include them via types or an import.
The important interfaces in that namespace:
JSX.IntrinsicElements— a map of built-in tag names to their props (div,button,svg). This is why<div foo={1} />is an error and<div className="x" />is not.JSX.Element— the type of a JSX expression (roughlyReact.ReactElementin React types).- Function components are checked as functions whose first argument is props and whose return is assignable to
JSX.Element | null(plus a few extras).
Lowercase tags look up IntrinsicElements. Uppercase tags look up the value in scope (Button). A typo <buton /> is an unknown intrinsic. A typo <Buton /> is an undeclared value.
key and ref are special. They are not always on your props type; React's types add them in the JSX check. Typing ref on a function component needs forwardRef or a ref prop you declared. The details have changed across React 18/19 types; follow the React types of your version.
jsxImportSource (for react-jsx) names the runtime module. The types of that module must exist. Changing it to preact or solid-js is how other JSX dialects hook in — they ship their own JSX namespace.
Do not set jsx to react and forget to import React in old JSX emit; react-jsx does not need that import. Do not mix .ts and JSX; the file must be .tsx (or allowJs plus .jsx).
JSX types are still erased. The emit is function calls. There is no runtime prop check unless you add one.
Code Examples
1. Intrinsics vs components.
// 1. Intrinsics vs components.
const a = <div className="box">hello</div>;
function Title(props: { text: string }) {
return <h1>{props.text}</h1>;
}
const b = <Title text="Hello" />;2. Modern React emit.
// 2. Modern React emit.
{
"compilerOptions": {
"jsx": "react-jsx",
"strict": true,
"lib": ["ES2022", "DOM"]
}
}3. A JSX expression's type is not a DOM node.
// 3. A JSX expression's type is not a DOM node.
function mount(): void {
const el = <Title text="Hi" />;
// document.body.appendChild(el);
// Error: el is a React element, not a Node. Use createRoot.
}Common Gotchas
JSX in a `.ts` file is a syntax error
rename to `.tsx`.
`jsx` emit and the `JSX` namespace are independent
you can emit `react-jsx` and still have no React types, or the reverse.
Lowercase vs uppercase is the intrinsic vs value split
`<div>` is HTML; `<Div>` is a component in scope.
A React element is not an `HTMLElement`
do not pass JSX to a DOM API without rendering it.