@typescript-eslint/no-unsafe-argument

Disallow passing a value of type any as an argument

needs types

Also called typescript-eslint/no-unsafe-argument, typescript/no-unsafe-argument

The compiler accepts any for every parameter. If you pass an any to a function that wants a number, nothing checks that it's a number. The function then runs with whatever came in.

The rule also reports any inside a generic type, such as a Set<any> passed where a Set<string> is expected, and spreading an any, an any[] or a tuple with an any element into the arguments.

bun lint --type-aware turns this rule on in TypeScript files.

Configure#

Off by default. This rule needs types, so turning it on makes bun lint type check your code first.

bunfig.toml
[lint.rules]
"@typescript-eslint/no-unsafe-argument" = "error" # or "warn"

Examples#

example.ts3 problems
declare function resize(width: number, height: number): void;
declare function addTags(tags: Set<string>): void;

const config = JSON.parse("{}");

resize(config.width, 100);
resize(...config.size);
addTags(new Set<any>());
example.tsNo problems
declare function resize(width: number, height: number): void;
declare function addTags(tags: Set<string>): void;

const config = JSON.parse("{}") as { width: number; size: [number, number] };

resize(config.width, 100);
resize(...config.size);
addTags(new Set<string>());

A parameter of type unknown or any accepts an any:

example.tsNo problems
declare function log(value: unknown): void;
declare function debug(value: any): void;

log(JSON.parse("{}"));
debug(JSON.parse("{}"));

When not to use it#

In a codebase that's still moving from JavaScript to TypeScript, any is everywhere and the reports drown out everything else. Turn the rule on once most values have real types.