no-unsafe-call
Disallow calling a value with type
any
.
Extending "plugin:@typescript-eslint/recommended-type-checked"
in an ESLint configuration enables this rule.
This rule requires type information to run.
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.
Despite your best intentions, the any
type can sometimes leak into your codebase.
Calling an any
-typed value as a function creates a potential type safety hole and source of bugs in your codebase.
This rule disallows calling any value that is typed as any
.
module.exports = {
"rules": {
"@typescript-eslint/no-unsafe-call": "error"
}
};
Try this rule in the playground ↗
Examples
- ❌ Incorrect
- ✅ Correct
declare const anyVar: any;
declare const nestedAny: { prop: any };
anyVar();
anyVar.a.b();
nestedAny.prop();
nestedAny.prop['a']();
new anyVar();
new nestedAny.prop();
anyVar`foo`;
nestedAny.prop`foo`;
Open in Playgrounddeclare const typedVar: () => void;
declare const typedNested: { prop: { a: () => void } };
typedVar();
typedNested.prop.a();
(() => {})();
new Map();
String.raw`foo`;
Open in PlaygroundOptions
This rule is not configurable.
When Not To Use It
If your codebase has many existing any
s or areas of unsafe code, it may be difficult to enable this rule.
It may be easier to skip the no-unsafe-*
rules pending increasing type safety in unsafe areas of your project.
You might consider using ESLint disable comments for those specific situations instead of completely disabling this rule.
Related To
Type checked lint rules are more powerful than traditional lint rules, but also require configuring type checked linting. See Troubleshooting > Linting with Type Information > Performance if you experience performance degredations after enabling type checked rules.