Back to Biomejs

noImplicitAnyLet

src/content/docs/linter/rules/no-implicit-any-let.mdx

latest4.0 KB
Original Source

import { Tabs, TabItem } from '@astrojs/starlight/components';

<Tabs> <TabItem label="TypeScript and TSX" icon="seti:typescript"> ## Summary - Rule available since: `v1.4.0` - Diagnostic Category: [`lint/suspicious/noImplicitAnyLet`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule doesn't have a fix. - The default severity of this rule is [**error**](/reference/diagnostics#error). ## How to configure ```json title="biome.json" { "linter": { "rules": { "suspicious": { "noImplicitAnyLet": "error" } } } }
## Description
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](https://www.typescriptlang.org/tsconfig#noImplicitAny) doesn't report this case.

## Examples

### Invalid

```ts
var a;
a = 2;
<pre class="language-text"><code class="language-text">code-block.ts:1:5 <a href="https://biomejs.dev/linter/rules/no-implicit-any-let">lint/suspicious/noImplicitAnyLet</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">This variable implicitly has the </span><span style="color: Tomato;"><strong>any</strong></span><span style="color: Tomato;"> type.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>var a; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong> <strong>2 │ </strong>a = 2; <strong>3 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Variable declarations without type annotation and initialization implicitly have the </span><span style="color: lightgreen;"><strong>any</strong></span><span style="color: lightgreen;"> type. Declare a type or initialize the variable with some value.</span> </code></pre>
ts
let b;
b = 1
<pre class="language-text"><code class="language-text">code-block.ts:1:5 <a href="https://biomejs.dev/linter/rules/no-implicit-any-let">lint/suspicious/noImplicitAnyLet</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">This variable implicitly has the </span><span style="color: Tomato;"><strong>any</strong></span><span style="color: Tomato;"> type.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>let b; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong> <strong>2 │ </strong>b = 1 <strong>3 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Variable declarations without type annotation and initialization implicitly have the </span><span style="color: lightgreen;"><strong>any</strong></span><span style="color: lightgreen;"> type. Declare a type or initialize the variable with some value.</span> </code></pre>

Valid

ts
var a = 1;
let a:number;
var b: number
var b =10;
</TabItem> </Tabs>