Disallow calling a function with a value with type any.
This rule applies only to .js and .ts files.
// code-linter.json5
{
"rules": {
"@typescript-eslint/no-unsafe-argument": "error"
}
} declare function foo(arg1: string, arg2: number, arg3: string): void;
foo('a', Number.MAX_VALUE, 'b');
const tuple1 = ['a', Number.MAX_VALUE, 'b'] as const;
foo(...tuple1);
declare function bar(arg1: string, arg2: number, ...rest: readonly string[]): void;
const array: string[] = ['a'];
bar('a', Number.MAX_VALUE, ...array);
declare function baz(arg1: Readonly<Set<string>>, arg2: Readonly<Map<string, string>>): void;
baz(new Set<string>(), new Map<string, string>()); declare function foo(arg1: string, arg2: number, arg3: string): void; const anyTyped = Number.MAX_VALUE as any; // The anyTyped variable is of the any type and cannot be passed in to the function as a parameter. foo(...anyTyped); // The anyTyped variable is of the any type and cannot be passed in to the function as a parameter. foo(anyTyped, Number.MAX_VALUE, 'a'); const anyArray: any[] = []; // The anyArray variable is an array of the any type. The array elements cannot be passed in to the function as parameters. foo(...anyArray); const tuple1 = ['a', anyTyped, 'b'] as const; // The anyTyped variable is an array of the any type. The array elements cannot be passed in to the function as parameters. foo(...tuple1);
plugin:@typescript-eslint/recommended plugin:@typescript-eslint/all
For details about how to configure Code Linter check rules, see Code Linter.