src/content/docs/linter/rules/no-explicit-any.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="TypeScript and TSX" icon="seti:typescript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/suspicious/noExplicitAny`](/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 [**warning**](/reference/diagnostics#warning). - Sources: - Same as [`@typescript-eslint/no-explicit-any`](https://typescript-eslint.io/rules/no-explicit-any){
"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;
class SomeClass {
message: Array<Array<any>>;
}
function fn(param: Array<any>): void {}
let variable: number = 1;
let variable2 = 1;
class SomeClass<T extends any> {
message: Array<Array<unknown>>;
}
function fn(param: Array<Array<unknown>>): Array<unknown> {}