Reference

TypeScript errors in JavaScript projects

Every error here comes with a failing example and a fixed one, both run through tsc when the site is built, so the message you see on the page is the message tsc prints, and each page says what the error means in a .js file.

They are grouped by what went wrong, and each group opens with a line on what its errors have in common. The code in each title is the one tsc prints, so searching the page for TS2322 finds it.

Types do not match

A value, an argument or a return value does not fit the type it was given: wrong types, missing or extra properties, argument counts, comparisons that can never be true.

Unknown names and members

A name, property or global the checker cannot find: typos, globals from a library the config leaves out, types used as values, and two scripts that declare the same name.

Null, undefined and unknown

A value that may be null or undefined (checked with strictNullChecks, part of strict), or that is typed unknown, has to be checked before it is used, and a variable has to be set before it is read.

Implicit any

noImplicitAny and noImplicitThis (both part of strict) report each place the checker would quietly fall back to any: untyped parameters, members, variables, lookups and this.

Modules and imports

Imports that do not resolve or do not match what the module exports, and the settings behind them: file extensions, CommonJS interop, top-level await, missing type declarations.

JavaScript files only

TypeScript syntax written in a .js file, and JSDoc that does not match the code next to it. Each page shows the JSDoc that does the same job.

Classes, JSX and unused code

Class member rules (@private, @readonly, @override, property initialization), the JSX setting, and the checks that report unused code and unused // @ts-expect-error comments.

The entries on this page are also published as data: diagnostics.json (about the data files).