Skip to content

noExplicitAny (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"suspicious": {
"noExplicitAny": "error"
}
}
}
}

Disallow the any type usage.

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 prevents an implied any, but doesn’t prevent any from being explicitly used the way this rule does.

Sometimes you can use the type unknown instead of the type any. It also accepts any value, however it requires to check that a property exists before calling it.

let variable: any = 1;
code-block.ts:1:15 lint/suspicious/noExplicitAny ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ Unexpected any. Specify a different type.

> 1 │ let variable: any = 1;
│ ^^^
2 │

ℹ any disables many type checking rules. Its use should be avoided.

ℹ Replace any with a specific type. If the type is not known, use unknown and narrow it before using the value.

class SomeClass {
message: Array<Array<any>>;
}
code-block.ts:2:25 lint/suspicious/noExplicitAny ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ Unexpected any. Specify a different type.

1 │ class SomeClass {
> 2 │ message: Array<Array<any>>;
│ ^^^
3 │ }
4 │

ℹ any disables many type checking rules. Its use should be avoided.

ℹ Replace any with a specific type. If the type is not known, use unknown and narrow it before using the value.

function fn(param: Array<any>): void {}
code-block.ts:1:26 lint/suspicious/noExplicitAny ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ Unexpected any. Specify a different type.

> 1 │ function fn(param: Array<any>): void {}
│ ^^^
2 │

ℹ any disables many type checking rules. Its use should be avoided.

ℹ Replace any with a specific type. If the type is not known, use unknown and narrow it before using the value.

let variable: number = 1;
let variable2 = 1;
class SomeClass<T extends any> {
message: Array<Array<unknown>>;
}
function fn(param: Array<Array<unknown>>): Array<unknown> {}