@typescript-eslint/no-unsafe-argument
Disallow passing a value of type any as an argument
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.
[lint.rules]
"@typescript-eslint/no-unsafe-argument" = "error" # or "warn"Examples#
declare function resize(width: number, height: number): void;
declare function addTags(tags: Set<string>): void;
const config = JSON.parse("{}");
resize(config.widthUnsafe argument of type any assigned to a parameter of type number., 100);
resize(...config.sizeUnsafe spread of an any type.);
addTags(new Set<any>()Unsafe argument of type Set<any> assigned to a parameter of type Set<string>.);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:
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.