@typescript-eslint/no-wrapper-object-types

Disallow String, Number, Boolean, BigInt, Symbol, and Object as types

warn by defaultfixable

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:

bunfig.toml
[lint.rules]
"@typescript-eslint/no-wrapper-object-types" = "off" # or "error"

Examples#

example.ts3 problems
function repeat(text: String, times: Number): String {
  return text.repeat(times.valueOf());
}
example.ts1 problem
function keysOf(record: Object) {
  return Object.keys(record);
}
example.tsNo problems
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:

example.tsNo problems
const port = Number("3000");
const label = String(port);