@typescript-eslint/no-wrapper-object-types
Disallow String, Number, Boolean, BigInt, Symbol, and Object as types
Also called typescript-eslint/no-wrapper-object-types, typescript/no-wrapper-object-types
The type Number isn't the type of 1. It describes the wrapper object that new Number(1) creates. A number fits into a Number, but not the other way around, so you can't pass a value typed Number to a function that takes a number. The same goes for String, Boolean, BigInt, and Symbol.
Object accepts almost every value, including strings and numbers. If you mean "not a primitive", use object.
--fix replaces the type with the lower-case one.
This rule is on by default in TypeScript files.
Configure#
On by default as a warning. To turn it off:
[lint.rules]
"@typescript-eslint/no-wrapper-object-types" = "off" # or "error"Examples#
function repeat(text: StringPrefer using the primitive string as a type name, rather than the upper-cased String., times: NumberPrefer using the primitive number as a type name, rather than the upper-cased Number.): StringPrefer using the primitive string as a type name, rather than the upper-cased String. {
return text.repeat(times.valueOf());
}function keysOf(record: ObjectPrefer using the primitive object as a type name, rather than the upper-cased Object.) {
return Object.keys(record);
}function repeat(text: string, times: number): string {
return text.repeat(times);
}
function keysOf(record: object) {
return Object.keys(record);
}Only types are checked. Calling the functions with the same names is fine:
const port = Number("3000");
const label = String(port);