Skip to content
Tutorials Center
My learning

Topics

TypeScript Reference ยท tsconfig: Type Checking Options

TypeScript noImplicitAny option

Reference for the TypeScript noImplicitAny option: when the compiler reports an implicit any, the common error codes, and the right ways to fix each case.

noImplicitAny makes the compiler report an error whenever it would silently give something the type any. Without the flag, a parameter with no annotation and no way to infer its type becomes any, and every operation on it goes unchecked. With the flag on, you must either write a type or give the compiler enough context to infer one.

It is part of strict and is the most important of the family: any is contagious, spreading through every expression it touches.

TypeScript
function double(n) {      // error TS7006: Parameter 'n' implicitly has an 'any' type.
  return n * 2;
}

Try it

TypeScript The error and the fix

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

TypeScript Ways to give the compiler a type

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

Syntax

JSON
{ "compilerOptions": { "noImplicitAny": true } }
TEXT
tsc --noImplicitAny
Error code Message (shortened) Typical cause
TS7006 Parameter 'x' implicitly has an 'any' type A function parameter without a type or a contextual type.
TS7005 Variable 'x' implicitly has an 'any' type A variable whose type cannot be determined.
TS7031 Binding element 'x' implicitly has an 'any' type A destructured parameter without a type.
TS7053 Element implicitly has an 'any' type because expression ... can't be used to index type Indexing an object with a key that its type does not cover.
TS7019 Rest parameter 'args' implicitly has an 'any[]' type ...args without a type.
TS7016 Could not find a declaration file for module An import of an untyped JavaScript package.

Edge cases: a variable declared with let x; and no initializer is allowed: it starts as "evolving any" and takes the type of what you assign, which is checked by control flow. It becomes an error (TS7034) only if it is captured by a closure before its type is settled.

Usage notes

  • Explicit any is still allowed. The flag only forbids implicit any. function f(x: any) compiles; ban explicit any with a lint rule such as @typescript-eslint/no-explicit-any.
  • Prefer unknown. It accepts any value but forces you to narrow before use, so callers keep the safety any would remove.
  • Contextual typing supplies parameter types in callbacks, array methods, event handlers and object literals assigned to typed variables, so annotations there are unnecessary.
  • Indexing errors (TS7053) are usually fixed with an index signature, Record<string, T>, or a keyof type guard, not with an assertion.
  • Untyped imports need an @types package or an ambient declare module.
  • JSON and fetch results are any from the library itself; annotate them or validate them at the boundary.