noImplicitAnyLet
¥Summary
-
规则生效日期:
v1.4.0¥Rule available since:
v1.4.0 -
诊断类别:
lint/suspicious/noImplicitAnyLet¥Diagnostic Category:
lint/suspicious/noImplicitAnyLet -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
¥How to configure
{ "linter": { "rules": { "suspicious": { "noImplicitAnyLet": "error" } } }}¥Description
禁止在变量声明中使用隐式 any 类型。
¥Disallow use of implicit any type on variable declarations.
没有任何类型注释和初始化的 TypeScript 变量声明具有 any 类型。TypeScript 中的任何类型都是类型系统中危险的“逃生舱”。使用 any 会禁用许多类型检查规则,通常最好只作为最后的手段或在原型代码时使用。TypeScript 的 --noImplicitAny 编译器选项 不会报告这种情况。
¥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
¥Invalid
var a;a = 2;code-block.ts: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 = 1code-block.ts: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
var a = 1;let a:number;var b: numbervar b =10;¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号