Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

TypeScript reports JSX elements as type any in a React project

ErrorJSX element implicitly has type 'any'

Short answer

TypeScript finds the types of JSX tags in the React type package. The error means those types are missing or not wired in. Install @types/react, set the jsx option in tsconfig.json, keep JSX in .tsx files, and in React 19 move custom JSX typings inside declare module react.

  • Applies to TypeScript 5.x, React 19
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    See whether the React type packages are installed and what the jsx option says.

    npm ls @types/react @types/react-dom
    grep -n "\"jsx\"" tsconfig*.json
  2. 2Match what you see, then jump to its fix

    1. 1npm ls shows no @types/reactThe React type definitions are not installedFix
    2. 2grep finds no jsx entryThe jsx option is not set in tsconfig.jsonFix
    3. 3The error appears in a .ts fileThe file containing JSX is not a .tsx fileFix
    4. 4A global.d.ts declares namespace JSX with custom element names; the error began after upgrading to React 19A custom JSX declaration no longer fits React 19Fix

What does the error look like?

  • JSX element implicitly has type 'any'
  • Tags such as div or span are underlined in red inside a .tsx file

Cause 1 of 4

The React type definitions are not installed

1Check

TypeScript learns what div, span and other tags accept from the React types.

npm ls @types/react

2Fix

Install both type packages as dev dependencies.

npm install --save-dev @types/react @types/react-dom

3Verify

Run the type check.

npx tsc --noEmit

Confirmed by react.dev

Did this fix it?

Cause 2 of 4

The jsx option is not set in tsconfig.json

1Check

To use JSX, TypeScript needs the jsx compiler option enabled.

grep -n "jsx" tsconfig.json

2Fix

Set it to react-jsx for the automatic runtime, or to preserve when a bundler handles JSX after TypeScript.

{
  "compilerOptions": {
    "jsx": "react-jsx"
  }
}

3Verify

Run the type check again.

npx tsc --noEmit

Confirmed by typescriptlang.org

Did this fix it?

Cause 3 of 4

The file containing JSX is not a .tsx file

1Check

Every file with JSX needs the .tsx extension.

grep -rln "</" src --include=*.ts

2Fix

Rename the file and update imports that name the extension.

git mv src/Button.ts src/Button.tsx

3Verify

Check types.

npx tsc --noEmit

Confirmed by react.dev

Did this fix it?

Cause 4 of 4

A custom JSX declaration no longer fits React 19

1Check

React 19 removed the global JSX namespace in favour of React.JSX. A declaration that only defines some intrinsic elements makes other names an error.

grep -rn "namespace JSX" src *.d.ts

2Fix

Put the augmentation inside declare module react, and use React.JSX.Element where the global JSX type was used.

// global.d.ts
declare module "react" {
  namespace JSX {
    interface IntrinsicElements {
      "my-element": { myElementProps: string };
    }
  }
}

3Verify

Run the type check.

npx tsc --noEmit

Confirmed by react.dev

Did this fix it?

How do I stop it coming back?

  • Create projects from the official templates, which set jsx and install the React types.
  • Keep @types/react on the same major version as react.
  • Run the React 19 types codemod when upgrading a TypeScript project.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

TypeScript rejects MUI Data Grid columns that set a type

A TypeScript error inside a column's renderCell callback

A columns array declared without a type is inferred with type as a plain string, which the Data Grid's column type union does not accept.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.