TypeScript errors

TypeScript compiler errors (TS2322, TS2345, TS7006…) explained with fixes for strict mode, generics and type declarations.

CodeErrorWhat it means
TS2564 TS2564: Property 'x' has no initializer and is not definitely assigned in the constructor With strictPropertyInitialization on, a class property declared without ? or a default isn’t set in the const…
TS2686: 'React' refers to a UMD global, but the current file is a module TypeScript: error TS2686: 'React' refers to a UMD global, but the current file is a module. Consider adding an import instead. JSX compiled with `jsx: react` needs `React` imported, but the file doesn't import it.
TS1128: Declaration or statement expected TypeScript: error TS1128: Declaration or statement expected. The parser found a token where a declaration or statement should start — usually stray braces/parentheses or…
TS1208: File cannot be compiled under '--isolatedModules' because it is considered a global script file TypeScript: error TS1208: 'index.ts' cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement With `isolatedModules`, every file must be a module (have an import or export).
TS17004: Cannot use JSX unless the '--jsx' flag is provided TypeScript: error TS17004: Cannot use JSX unless the '--jsx' flag is provided. A `.tsx` file contains JSX but tsconfig has no `jsx` option.
TS1259: Module can only be default-imported using the 'esModuleInterop' flag TypeScript: error TS1259: Module '"express"' can only be default-imported using the 'esModuleInterop' flag You default-import a CommonJS module that uses `export =`, but `esModuleInterop` isn't enabled.
TS1005: ';' expected / ',' expected (syntax error) TypeScript: error TS1005: ';' expected. The parser hit a syntax error — missing punctuation, mismatched brackets, or an unsupported syntax for your T…
TS2366: Function lacks ending return statement TypeScript: error TS2366: Function lacks ending return statement and return type does not include 'undefined'. A function with a declared return type can reach its end without returning on some path.
TS1484/TS1205: type must be imported using a type-only import TypeScript: error TS1484: 'User' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled. With `verbatimModuleSyntax` or `isolatedModules`, types must be imported/re-exported with `import type` / `ex…
TS2305: Module has no exported member TypeScript: error TS2305: Module '"./utils"' has no exported member 'helper'. You imported a named export that the module doesn't export.
TS2551: Property does not exist. Did you mean TypeScript: error TS2551: Property 'lenght' does not exist on type 'string'. Did you mean 'length'? A property name is misspelled (TypeScript suggests the closest valid one).
TS2578: Unused '@ts-expect-error' directive TypeScript: error TS2578: Unused '@ts-expect-error' directive. A `// @ts-expect-error` comment suppresses nothing because the next line no longer has an error.
TS2451: Cannot redeclare block-scoped variable TypeScript: error TS2451: Cannot redeclare block-scoped variable 'name'. A `let`/`const`/`class` name was declared twice in the same scope — often because files are global scripts sh…
TS2688: Cannot find type definition file for 'x' TypeScript: error TS2688: Cannot find type definition file for 'node'. `types` in tsconfig (or auto-included `@types/*`) refers to a package that isn't installed.
TS2454: Variable is used before being assigned TypeScript: error TS2454: Variable 'x' is used before being assigned. Control flow shows a path where the variable is read before any assignment.
TS2322 TS2322: Type 'X' is not assignable to type 'Y' You assigned a value whose type doesn’t match the declared type of the variable, property or return value.
TS7006 TS7006: Parameter 'x' implicitly has an 'any' type A function parameter has no type annotation and TypeScript can’t infer one, which noImplicitAny (part of stri…
TS2353: Object literal may only specify known properties TypeScript: error TS2353: Object literal may only specify known properties, and 'nmae' does not exist in type 'User' An object literal has an extra (or misspelled) property not in the target type (excess property check).
TS2503: Cannot find namespace 'X' TypeScript: error TS2503: Cannot find namespace 'JSX'. / Cannot find namespace 'NodeJS' Code references a global namespace (JSX, NodeJS, Express) that isn't declared — missing `@types` or lib setti…
TS2792: Cannot find module — did you mean to set the 'moduleResolution' option to 'nodenext' TypeScript: error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? TypeScript can't resolve a package because `moduleResolution` doesn't match how the package exports (package…
TS2802: Type can only be iterated through when using the '--downlevelIteration' flag TypeScript: error TS2802: Type 'Set<string>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher You iterate a Set/Map/generator with an old compile target (ES5) where `for...of`/spread aren't natively supp…
TS4023/TS2742: exported variable has or is using name from external module but cannot be named TypeScript: error TS4023: Exported variable 'x' has or is using name 'Foo' from external module "..." but cannot be named. / TS2742: The inferred type cannot be named without a reference With `declaration: true`, TypeScript can't write the inferred type into `.d.ts` because it refers to a type i…
TS6059: File is not under 'rootDir' TypeScript: error TS6059: File '/app/shared/util.ts' is not under 'rootDir' '/app/src'. 'rootDir' is expected to contain all source files. A source file lives outside the configured `rootDir`, so `tsc` can't preserve the output structure.
TS2393: Duplicate function implementation TypeScript: error TS2393: Duplicate function implementation. A function with the same name/signature is implemented more than once in the same scope.
TS2589: Type instantiation is excessively deep and possibly infinite TypeScript: error TS2589: Type instantiation is excessively deep and possibly infinite. The compiler hit its recursion limit while evaluating a very complex or recursive generic type.
TS2352: Conversion of type may be a mistake TypeScript: error TS2352: Conversion of type 'string' to type 'number' may be a mistake because neither type sufficiently overlaps with the other A type assertion (`as`) between unrelated types was rejected.
TS2367: This comparison appears to be unintentional TypeScript: error TS2367: This comparison appears to be unintentional because the types '"a" | "b"' and '"c"' have no overlap. You compare two values whose types can never be equal.
TS2531: Object is possibly 'null' TypeScript: error TS2531: Object is possibly 'null'. You used a value that can be `null` without checking it first (strictNullChecks).
TS2604: JSX element type does not have any construct or call signatures TypeScript: error TS2604: JSX element type 'Foo' does not have any construct or call signatures. You used something as a JSX component that TypeScript doesn't see as a component (not a function/class return…
TS2614: Module has no exported member — did you mean to use 'import x from' TypeScript: error TS2614: Module '"./Button"' has no exported member 'Button'. Did you mean to use 'import Button from "./Button"' instead? You used a named import for something that's a default export (or reverse).
TS5083: Cannot read file tsconfig.json / extends not found TypeScript: error TS5083: Cannot read file '/app/tsconfig.json'. / error TS6053: File 'tsconfig.base.json' not found tsc/your IDE can't find or parse the tsconfig (wrong directory, bad `extends`, JSON error).
TS7005: Variable implicitly has an 'any' type TypeScript: error TS7005: Variable 'x' implicitly has an 'any[]' type. / TS7034: Variable implicitly has type 'any' in some locations With `noImplicitAny`, a variable's type can't be inferred and defaults to `any`.
TS7031: Binding element implicitly has an 'any' type TypeScript: error TS7031: Binding element 'name' implicitly has an 'any' type. A destructured parameter has no type, so its elements default to `any`.
TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index TypeScript: error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ a: number; }' You index an object with a general `string` key, but its type only knows specific keys.
TS2349: This expression is not callable TypeScript: error TS2349: This expression is not callable. Type 'X' has no call signatures. You called something TypeScript believes isn't a function (a union without compatible signatures, a module na…
TS2403: Subsequent variable declarations must have the same type TypeScript: error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'number'. A `var` was redeclared with a different type (or global declarations conflict).
TS2420: Class incorrectly implements interface TypeScript: error TS2420: Class 'Dog' incorrectly implements interface 'Animal'. Property 'speak' is missing in type 'Dog' but required in type 'Animal' A class declared `implements X` doesn't provide every required member (or with matching types).
TS2430: Interface incorrectly extends interface TypeScript: error TS2430: Interface 'B' incorrectly extends interface 'A'. Types of property 'x' are incompatible An extending interface redefines a property with a type that isn't assignable to the base's.
TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or 'es2015' or later TypeScript: error TS5095 `moduleResolution: "bundler"` needs a compatible `module` setting.
TS6133: 'x' is declared but its value is never read TypeScript: error TS6133: 'x' is declared but its value is never read. `noUnusedLocals`/`noUnusedParameters` flag an unused variable, import or parameter.
TS2502/TS7022: referenced directly or indirectly in its own initializer TypeScript: error TS7022: 'x' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer A variable's inferred type depends on itself (circular inference).
TS1192: Module has no default export TypeScript: error TS1192: Module '"./utils"' has no default export. You used `import x from "./mod"` but the module only has named exports.
TS18046: 'x' is of type 'unknown' TypeScript: error TS18046: 'e' is of type 'unknown'. (catch variable) TypeScript 4.9+ reports `unknown` values with their name; most often the `catch (e)` variable.
TS18048: 'x' is possibly 'undefined' TypeScript: error TS18048: 'user' is possibly 'undefined'. A value that may be `undefined` is used without a check (TS 4.9+ message with the variable name).
TS2554: Expected N arguments, but got M TypeScript: error TS2554: Expected 2 arguments, but got 1. A call passes too few or too many arguments.
TS2571: Object is of type 'unknown' TypeScript: error TS2571: Object is of type 'unknown'. You used a value typed `unknown` (often `catch (e)` or `JSON.parse` result) without narrowing.
TS2693: 'X' only refers to a type, but is being used as a value here TypeScript: error TS2693: 'User' only refers to a type, but is being used as a value here. You used an interface/type alias where a runtime value is needed.
TS2741: Property is missing in type but required in type TypeScript: error TS2741: Property 'email' is missing in type '{ name: string; }' but required in type 'User'. An object lacks one required property of the target type.
TS2769: No overload matches this call TypeScript: error TS2769: No overload matches this call. Overload 1 of 2, '(a: string): void', gave the following error. A call matched none of the function's overload signatures.
TS2379/TS2375: exactOptionalPropertyTypes error TypeScript: error TS2379: Argument of type '{ name: string; age: undefined; }' is not assignable to parameter of type 'User' with 'exactOptionalPropertyTypes: true' With `exactOptionalPropertyTypes`, an optional property (`age?: number`) can be omitted but not explicitly se…
TS2416: Property in type is not assignable to the same property in base type TypeScript: error TS2416: Property 'render' in type 'Child' is not assignable to the same property in base type 'Base' A subclass overrides a member with an incompatible type.
TS2740: Type is missing the following properties TypeScript: error TS2740: Type '{ name: string; }' is missing the following properties from type 'User': id, email An object doesn't provide all required properties of the target type.
TS2300: Duplicate identifier TypeScript: error TS2300: Duplicate identifier 'Foo'. The same name is declared twice in the same scope (or in merged global declarations).