noImplicitAnyLet (since v1.4.0)
Diagnostic Category: lint/suspicious/noImplicitAnyLet
Disallow use of implicit any
type on variable declarations.
TypeScript variable declaration without any type annotation and initialization have the any
type.
The any type in TypeScript is a dangerous “escape hatch” from the type system.
Using any disables many type checking rules and is generally best used only as a last resort or when prototyping code.
TypeScript’s --noImplicitAny
compiler option doesn’t report this case.
Examples
Section titled ExamplesInvalid
Section titled Invalidvar a;a = 2;
suspicious/noImplicitAnyLet.js:1:5 lint/suspicious/noImplicitAnyLet ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This variable implicitly has the any type.
> 1 │ var a;
│ ^
2 │ a = 2;
3 │
ℹ Variable declarations without type annotation and initialization implicitly have the any type. Declare a type or initialize the variable with some value.
let b;b = 1
suspicious/noImplicitAnyLet.js:1:5 lint/suspicious/noImplicitAnyLet ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This variable implicitly has the any type.
> 1 │ let b;
│ ^
2 │ b = 1
3 │
ℹ Variable declarations without type annotation and initialization implicitly have the any type. Declare a type or initialize the variable with some value.
Valid
Section titled Validvar a = 1;let a:number;var b: numbervar b =10;