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.
-
TS2322: A value does not match its declared type
TS2322 means a value has a different type from the one its JSDoc annotation declares. How to read the message in a .js file and fix the value or the type.
-
TS2345: An argument does not match the parameter's type
TS2345 means a call passes an argument of the wrong type. The two usual causes in JavaScript, form text and possibly undefined values, and their fixes.
-
TS2353: An object literal has a property its type does not know
TS2353 is the excess property check: an object literal names a property the target type lacks, usually a typo in an options object. How to fix it in JSDoc.
-
TS2741: An object is missing a required property
TS2741 means an object lacks one property its type requires. Add the property, or mark it optional in the @typedef with brackets.
-
TS2739: An object is missing several required properties
TS2739 lists the required properties an object lacks; TS2740 also counts the rest. Complete the object, use Partial, or cast a test stand-in.
- Also TS2740
-
TS2355: A function with a return type never returns a value
TS2355 means @returns promises a value and the function body never returns one. Usually a forgotten return; sometimes a @type that sets the return type.
-
TS2366: A function can reach its end without returning
TS2366 means a path through a function ends without a return while @returns excludes undefined. Why an if chain over every case still trips it.
strictNullChecksstrict
-
TS2362: Arithmetic on something that is not a number
TS2362 and TS2363 mean one side of -, *, / or % is not a number: usually a Date or a form field's text. Convert it with getTime() or Number().
- Also TS2363
-
TS2365: An operator cannot be used with these types
TS2365 means a comparison or + mixes types the checker will not combine, such as a Date with a number or text with a number. Compare numbers with numbers.
-
TS2367: A comparison that can never be true
TS2367 means === or !== compares types that share no value, so the result never changes. Usually a misspelled literal or a number compared with a string.
-
TS2769: No overload matches the call
TS2769 means a function with several signatures was called with arguments none of them accept. How to read the per-overload lines and fix the argument.
-
TS2554: The wrong number of arguments
TS2554 and TS2555 mean a call passes too few or too many arguments. In JavaScript, @param tags make parameters required; brackets make one optional.
- Also TS2555
-
TS2556: Spreading an array into fixed parameters
TS2556 means ...array was passed to parameters that need an exact count. Type the array as a tuple, use a const cast, or give the function a rest parameter.
-
TS2488: A value that is not iterable
TS2488 means for...of, array destructuring or spread was used on something that is not iterable, usually a plain object. Loop over Object.entries instead.
-
TS2561: An unknown property in an object literal, with a suggestion
TS2561 is the excess property check with a spelling hint: an object literal names a property its type lacks, and a close one exists. Use the suggested name.
-
TS2684: A function called with the wrong this
TS2684 means a function that declares its this (with @this, or as a method) is called with a different one, often a plain call. Call it with the right this.
-
TS1064: An async function whose return type is not a Promise
TS1064 means an async function is annotated with a return type that is not a Promise, often @returns {string}. Write @returns {Promise<string>}.
-
TS2775: An assertion function called through an untyped name
TS2775 means an assertion function is called through a name with no declared type, such as a property of an untyped object. Call it directly or type the object.
-
TS7030: A path that returns no value, under noImplicitReturns
TS7030 means a function returns a value on some paths and falls off the end on others, with noImplicitReturns on. Return a value on every path.
noImplicitReturns
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.
-
TS2304: A name the checker cannot find
TS2304 means a name is used that no file in the program declares: often a global a script tag or bundler adds. Declare it in a .d.ts file the config includes.
-
TS2339: A property the type does not have
TS2339 means code reads a property its type does not declare: window.dataLayer, a field added later, a typo with no close match. Declare it or type the object.
-
TS2551: A misspelled property, with a suggestion
TS2551 means a property does not exist but one with a similar name does, so the checker suggests it. Accept the quick fix, or declare the property you meant.
-
TS2552: A misspelled name, with a suggestion
TS2552 means a variable or function name is not declared but a similar one is. Usually a case or spelling slip: use the suggested name.
-
TS2451: Two files declare the same top-level name
TS2451 across files means the checker treats your .js files as scripts sharing one global scope. Fix with moduleDetection force, an empty export, or a block.
-
TS2693: A type used where JavaScript needs a value
TS2693 means a name that only exists as a type, such as a @typedef or a pasted type argument, is used in running code. Use a type guard or a JSDoc tag instead.
-
TS2694: An import() type names something the module does not export
TS2694 in JavaScript usually comes from an import() type in JSDoc whose name the module does not export: a typo, or a type the package calls something else.
-
TS2583: Map, Set or Promise is missing because the target is old
TS2583 and TS2585 mean Map, Set, Promise or Symbol are missing because the config targets ES5, the 5.9 default when no target is set. Set target.
- Also TS2585
-
TS2584: console is missing because lib leaves out the DOM
TS2584 means console or document is unknown: lib lists only ECMAScript libraries and no Node.js types are loaded. Add @types/node or the dom library.
-
TS2550: A method newer than the configured library
TS2550 means a built-in method such as .at() or replaceAll() is newer than the target or lib the config names. Raise target if your runtimes support the method.
-
TS2582: Test globals without the test runner types
TS2582 means a test file uses describe, it or test and no test runner declares them. Load the runner's global types, or import the functions.
- Also TS2593
-
TS4111: Dot access to an index signature
TS4111 means a property that only an index signature allows is read with a dot, under noPropertyAccessFromIndexSignature. Use brackets, or declare it.
noPropertyAccessFromIndexSignature
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.
-
TS2531: A lookup that may return null, used without a check
TS2531 means an expression that may be null, such as document.querySelector(...) or localStorage.getItem(...), is used without a check. Three ways to handle it.
strictNullChecksstrict
-
TS18047: A variable that may be null, used without a check
TS18047 means a variable whose type includes null is used without a check, typically an element from querySelector. Check it once, early.
strictNullChecksstrict
-
TS2532: A call that may return undefined, used without a check
TS2532 means a property is read on an expression that may be undefined, most often array.find(...). Handle the missing case, or use ?. with a fallback.
strictNullChecksstrict
-
TS18048: A variable that may be undefined, used without a check
TS18048 means a variable or optional parameter that may be undefined is used without a check. Check it, give it a default, or say why it is always set.
strictNullChecksstrict
-
TS2722: Calling an optional function without a check
TS2722 means an optional callback or method is called without checking it exists. Call it with ?.() or give it a no-op default.
strictNullChecksstrict
-
TS2538: undefined used as an object key
TS2538 means a value used as an object key in brackets may be undefined (or is another type that cannot be a key). Pick a fallback key or check first.
strictNullChecksstrict
-
TS18046: A value of type unknown is used without a check
TS18046 means a variable typed unknown, most often the error in a catch clause, is used before it is narrowed. Check it with instanceof or typeof first.
useUnknownInCatchVariablesstrict- Also TS2571
-
TS2454: A variable is read before it is set
TS2454 means a typed variable is read on a path where no value was assigned to it. Give it a starting value, or assign it on every branch.
strictNullChecksstrict
-
TS2375: undefined in an optional property, under exactOptionalPropertyTypes
TS2375 means an optional property is set to undefined while exactOptionalPropertyTypes is on. Leave the property out, or add undefined to its type.
exactOptionalPropertyTypes- Also TS2379
- Also TS2412
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.
-
TS7006: Parameter implicitly has an 'any' type
TS7006 means a parameter has no type and TypeScript cannot infer one. Why it shows up in checked JavaScript under strict, and the ways to fix it.
noImplicitAnystrict
-
TS7008: A class field without a type
TS7008 means a class field has no type the checker can use: declared bare, or only ever set to an empty array or null. Add a @type tag above the field.
noImplicitAnystrict
-
TS7017: Reading a global through globalThis that nothing declares
TS7017 in JavaScript is usually globalThis.SOMETHING that no file declares: a flag or config a script tag sets. Declare it with var in a .d.ts file.
noImplicitAnystrict
-
TS7023: A recursive function needs a return type
TS7023 and TS7022 mean the checker cannot infer a type because it depends on itself: a recursive function, or a variable set from that function. Add @returns.
noImplicitAnystrict- Also TS7022
-
TS7031: A destructured parameter without a type
TS7031 means a destructured parameter such as { name, email } has no type, so each name is reported. One @param tag for the whole object fixes them all.
noImplicitAnystrict
-
TS7034: A variable whose type cannot be settled
TS7034 and TS7005 mean a variable started as [], null or nothing and the checker cannot follow its type, often because a closure uses it. Annotate the variable.
noImplicitAnystrict- Also TS7005
-
TS7053: Indexing an object with a string key
TS7053 means obj[key] uses a string key on an object whose type lists fixed properties. Type the key as keyof typeof obj, or the object as a Record.
noImplicitAnystrict
-
TS2683: this has no type in a plain function
TS2683 means a function that is not a method uses this, so the checker does not know what this is. Declare it with @this, or use event.currentTarget.
noImplicitThisstrict
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.
-
TS2307: An import the checker cannot resolve
TS2307 means an import path resolves to nothing the checker can read: a package not installed, a typo, or a CSS or image file. Install it or declare the module.
-
TS2305: Importing a name the module does not export
TS2305 means a named import asks for something the module does not export; TS2724 adds a spelling suggestion. Fix the name, or export it from the module.
- Also TS2724
-
TS2614: A named import of a default export
TS2614 means import { name } was used for a default export; TS2613 is the reverse, a default import of named exports. Match the import to the export.
- Also TS2613
-
TS2792: Packages not found because module resolution is classic
TS2792 means module set to an ES year without moduleResolution left TypeScript 5.9 on its old classic lookup, which misses most packages. Set moduleResolution.
-
TS1259: A default import of a CommonJS module without interop
TS1259 means import x from a CommonJS package (export =) without esModuleInterop or allowSyntheticDefaultImports. A jsconfig.json allows it by default.
-
TS2835: A relative import without its file extension
TS2835 and TS2834 mean an ES module imports ./file or ./folder without .js under nodenext, which Node.js does not resolve. Write the full path, or use bundler.
- Also TS2834
-
TS1378: Top-level await with an older module setting
TS1378 means await at the top of a module, with module or target set too old for it, often because module is missing. Set module to nodenext or es2022.
-
TS2580: Node.js globals without the Node.js types
TS2580 means process, Buffer, module or another Node.js global is used and @types/node is not installed. Install it as a dev dependency.
-
TS2591: Node.js globals with node missing from types
TS2591 means a Node.js global is used and the config's types list does not include node. Add "node" to types (and install @types/node if needed).
-
TS7016: A package without type declarations
TS7016 means an imported package ships JavaScript without types and the checker does not read it. Install @types, write a small .d.ts, or let it read the JS.
noImplicitAnystrict
-
TS1543: A JSON import without the import attribute
TS1543 means an ES module imports a JSON file without with { type: "json" } under module nodenext. Add the attribute; TS1544 says to use the default import.
- Also TS1544
-
TS2880: assert on an import, where with is required
TS2880 means an import uses the old assert { type: "json" } syntax under module nodenext. Write with instead of assert; nothing else changes.
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.
-
TS8010: TypeScript annotations in a .js file
TS8010 means TypeScript syntax such as name: string was written in a .js file, usually pasted from a .ts file. Move the types into JSDoc tags.
- Also TS8004
-
TS8016: An as cast in a .js file
TS8016 and TS8037 mean as or satisfies was written in a .js file. The JSDoc spellings are a parenthesized @type cast and the @satisfies tag.
- Also TS8037
-
TS8013: The ! operator in a .js file
TS8013 means TypeScript's postfix ! ("this is not null") was written in a .js file. Check the value instead, or cast it with a JSDoc @type.
-
TS8006: interface, enum or namespace in a .js file
TS8006 means an interface, enum or namespace declaration was written in a .js file. Use @typedef for shapes and a frozen object with @enum for values.
-
TS8008: A type alias in a .js file
TS8008 means type Name = ... was written in a .js file. The JSDoc spelling is a @typedef with the same type in braces, usable from any file.
-
TS8009: private, readonly or another TypeScript modifier in a .js file
TS8009 means a TypeScript-only modifier (private, public, readonly, abstract, declare, ?) was used in a .js file. Use #private fields or the JSDoc tags.
-
TS8024: A @param tag that names no parameter
TS8024 means a @param tag's name matches no parameter, usually after a rename. The parameter is then untyped too (TS7006). Rename the tag.
-
TS8023: An @extends tag that does not match the extends clause
TS8023 means a class's @extends (or @augments) tag names a different class from its extends clause. The tag should repeat the class, adding type arguments.
-
TS1247: An initializer in a type literal, often a Closure = in JSDoc
TS1247 in JSDoc usually means an old Closure-style optional marker, unit: string=, inside an object type. Write unit?: string instead.
-
TS18042: A type imported with import in a .js file
TS18042 means a .js file imports a type by name with an import statement. Types come in through @import or import() types; the import is a runtime one.
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.
-
TS2341: Using a @private member from outside its class
TS2341 and TS2445 mean code outside a class uses a member marked @private or @protected. Go through a public method, or use a real #private field.
- Also TS2445
-
TS2540: Assigning to a read-only property
TS2540 means code assigns to a property typed read-only: a @readonly field, a frozen object, a Readonly type. Set it in the constructor or copy the object.
-
TS2564: A typed field the constructor never sets
TS2564 means a class field has a @type that excludes undefined but no value and no assignment in the constructor. Initialize it or include undefined.
strictPropertyInitializationstrict
-
TS4119: An override without the @override tag
TS4119 means noImplicitOverride is on and a subclass method replaces a base class method without an @override tag. Add the tag above the method.
noImplicitOverride
-
TS4122: @override on a member the base class does not have
TS4122 means a member is tagged @override but the base class has no member of that name: a typo, a rename in the base, or a new method. Fix or drop the tag.
-
TS2578: A // @ts-expect-error with nothing to expect
TS2578 means a // @ts-expect-error comment sits above a line that no longer has an error. Remove the comment; that is the directive doing its job.
-
TS6133: A variable, import or parameter that is never read
TS6133 means an import, variable or parameter is never read, under noUnusedLocals or noUnusedParameters. Remove it, or prefix a parameter with _.
noUnusedLocalsnoUnusedParameters
-
TS17004: JSX without a jsx setting
TS17004 means a .jsx file (or JSX in a .js file) is checked with no jsx option. Set jsx to preserve or react-jsx to match what your bundler does.
-
TS7026: JSX elements without JSX types
TS7026 means JSX is checked but no JSX types are loaded, so every element is any. Install your framework's types, or declare JSX.IntrinsicElements.
noImplicitAnystrict
-
TS2416: A subclass member that does not fit the base class
TS2416 means a subclass overrides a method or property with a type the base class's version does not allow. Keep the override compatible with the base.
-
TS2420: A class that does not match its @implements type
TS2420 means a class tagged @implements is missing a member of that type, or one does not fit. Add the member, or fix its type.
-
TS18013: A #private field read from outside its class
TS18013 means code outside a class reads a #private field. JavaScript itself forbids it; expose what callers need through a method or getter.
The entries on this page are also published as data: diagnostics.json (about the data files).