Banned TypeScript Types

ID

javascript.ts_ban_types

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Best Practice

Language

JavaScript

Tags

best-practice, type-safety, typescript

Description

Reports TypeScript type references whose name is the capitalised boxed-primitive constructor or Function, plus the empty object type {}:

function f(value: Object): String { ... }       // FLAW + FLAW
const cb: Function = () => { ... };             // FLAW
const data: {} = read();                        // FLAW

Rationale

The capitalised names are the JavaScript constructor functions — boxed wrappers around primitives — not the primitive types developers usually mean:

  • Object matches every non-null/undefined value, including primitives. It does not enforce that the value is a "plain object".

  • String, Number, Boolean, Symbol, BigInt refer to the wrapper objects produced by new String(…​), etc. Their typeof is "object", not the matching primitive.

  • Function is a generic callable with no signature information. Code using it cannot tell what arguments to pass or what the return type is.

  • {} matches every non-null/undefined value, just like Object. It is rarely what the developer meant.

The fix is to switch to the matching lowercase primitive (string, number, boolean, symbol, bigint), to use a specific interface, or to write a precise function signature.

Remediation

Use the matching primitive or a specific shape:

function f(value: string): string { ... }
const cb: () => void = () => { ... };
interface UserData { id: string; name: string; }
const data: UserData = read();

For "any non-primitive value", use the lowercase object. For "any value at all", unknown is the safe choice (with explicit narrowing); avoid any if possible.

Notes

The lowercase primitives are recognised as PredefinedType in the AST and are not flagged. The rule fires once per banned type reference. Generics (Array<string>) are still reported when the referenced name itself is banned, but their type arguments are not affected.