noImplicitAny
Errors whenever TypeScript would silently fall back to any for an untyped parameter or member.
"noImplicitAny": boolean // Default: true if strict; false otherwise- Added in TypeScript 1.0
Parameters
| Parameter | Type | Description |
|---|---|---|
$noImplicitAnyoptional | boolean= true if strict; false otherwise | When true, TypeScript raises an error anywhere it would have inferred the type any because no annotation was present and no type could be inferred. |
Errors
Nothing at runtime; it reports error 7006 for parameters, 7005/7008 for variables and members, and 7053 for unindexable element access.
Changelog
- PHP 5.5suppressImplicitAnyIndexErrors, the old escape hatch for index-access errors under this flag, no longer has any effect.
Where no annotation is present and nothing can be inferred, TypeScript falls back to any. any disables checking entirely for that value, so the fallback quietly creates holes. noImplicitAny turns each of those holes into an error.
Where it fires
- Function and method parameters with no annotation and no contextual type
letor class members declared with no type and no initialiser to infer from- Indexing an object with a
stringwhen the object has no index signature (error 7053) .jsfiles, oncecheckJsis on
What trips people up
It is implicit any that is banned, not any. Writing function fn(s: any) still compiles — the flag only forces you to make the decision visible. Callback parameters are usually fine without annotations because they get a contextual type from the function they are passed to; if one errors, the surrounding call is not typed the way you think. And the flag never touches values inferred as any from an untyped dependency; for those you want a .d.ts or an explicit annotation.
Example
// "noImplicitAny": true
// function fn(s) { ... }
// Error 7006: Parameter 's' implicitly has an 'any' type.
function fn(s: string): number {
return s.length;
}
// Callback parameters are contextually typed, so no annotation is needed:
const lengths = ["a", "bb", "ccc"].map((word) => fn(word));
console.log(fn("typescript")); // 10
console.log(lengths); // [ 1, 2, 3 ]When to use it
- Making sure every exported function's parameters are actually typed
- Finding the untyped seams where a JavaScript module was ported to TypeScript
- Catching obj[key] lookups on a type that has no index signature
Frequently asked questions
How do I fix 'Parameter implicitly has an any type' (ts7006)?
Annotate the parameter with the type it is actually called with, for example function fn(s: string). If it genuinely can be anything, write : unknown and narrow inside, or : any to opt out explicitly — the flag only forbids leaving it unwritten.
Does noImplicitAny ban the any type?
No. It bans TypeScript inferring any silently. An explicit : any annotation compiles fine under this flag; use the no-explicit-any lint rule if you want to ban the type itself.
Why do my callback parameters not need annotations?
They get a contextual type from the function they are passed to — array.map knows its callback receives an element. If a callback parameter does error under this flag, the value you are calling the method on is untyped, and that is the real problem to fix.
More examples
The bug the flag exists to catch
Prints "cript". The commented version prints nothing — it throws TypeError: s.subtr is not a function — which is exactly the failure the flag converts into a compile error.
// With noImplicitAny off, `s` is any and this compiles clean:
//
// function fn(s) {
// console.log(s.subtr(3)); // no error
// }
// fn(42);
//
// With the flag on, tsc reports 7006 on `s`, and once you annotate
// it `s: string`, the misspelling and the call site both fail too.
function fn(s: string) {
console.log(s.substr(3)); // substr, not subtr
}
fn("typescript"); // -> criptIndex access under the flag
The cast is what makes the lookup legal. The third log shows why tsc objected in the first place: an arbitrary string key can miss, and the declared return type says nothing about that.
const config = { host: "localhost", port: 8080 };
function get(key: string) {
// config[key] is error 7053 under noImplicitAny:
// no index signature with a parameter of type 'string'.
return (config as Record<string, string | number>)[key];
}
console.log(get("host")); // localhost
console.log(get("port")); // 8080
console.log(get("user")); // undefined
Discussion