@typescript-eslint/no-explicit-any

Disallow the any type

warn by defaultfixable

Also called typescript-eslint/no-explicit-any, typescript/no-explicit-any

any turns type checking off for a value, and for everything computed from it. You can call it, read any property of it and pass it anywhere, and a typo only shows up when the code runs. unknown also accepts every value, but you have to narrow it before you use it.

This rule is on by default in TypeScript files.

Configure#

On by default as a warning. To turn it off:

bunfig.toml
[lint.rules]
"@typescript-eslint/no-explicit-any" = "off" # or "error"

Every option, set to its default:

bunfig.toml
[lint.rules]
"@typescript-eslint/no-explicit-any" = ["warn", {
  fixToUnknown = false,
  ignoreRestArgs = false,
}]

Examples#

example.ts1 problem
function parse(text: string): any {
  return JSON.parse(text);
}

parse("{}").user.nmae; // no type error
example.tsNo problems
function parse(text: string): unknown {
  return JSON.parse(text);
}

const result = parse("{}");
if (typeof result === "string") {
  console.log(result.length);
}

Options#

OptionDefaultWhat it does
fixToUnknownfalseLet --fix rewrite any to unknown, and keyof any to PropertyKey. The code may stop compiling until you narrow the values.
ignoreRestArgsfalseAllow any[], Array<any> and their readonly forms as the type of a rest parameter.
example.tswith { "ignoreRestArgs": true }No problems
function log(...args: any[]) {
  console.log(...args);
}

Every other any is still reported:

example.tswith { "ignoreRestArgs": true }1 problem
function log(message: any) {
  console.log(message);
}