Some built-in types don't mean what they look like:
String,Number,Boolean,Symbol, andBigIntare the wrapper objects. You almost always want the lowercasestring,number,boolean,symbol, orbigint.Functionaccepts any function, and calling it returnsany, so arguments and results aren't checked.Objectand{}accept every value exceptnullandundefined, including0and"".
Names that a class implements or an interface extends aren't reported.
Configure
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"@typescript-eslint/ban-types" = "error" # or "warn"
Examples
Reported:
function greet(name: String, onDone: Function) {
onDone(`Hello, ${name}`);
}
let settings: {} = 0;
let extra: Object = "";
Not reported:
function greet(name: string, onDone: (message: string) => void) {
onDone(`Hello, ${name}`);
}
let settings: Record<string, unknown> = {};
let extra: object = {};
interface Handler extends Function {
priority: number;
}
When not to use it
Three newer rules split up the same checks, so you can turn each one on separately: @typescript-eslint/no-wrapper-object-types, @typescript-eslint/no-unsafe-function-type, and @typescript-eslint/no-empty-object-type.