Skip to content
Tutorials Center
My learning

Topics

TypeScript Reference ยท Primitive and Special Types

TypeScript Object and {} types

Understand the capital-O Object type and the empty type {} in TypeScript: they accept nearly every value except null and undefined, so use them with care.

Object (capital O) and {} are two types that surprise newcomers. Both mean "any value that is not null or undefined". That includes strings, numbers, booleans and symbols, because primitives can use members from Object.prototype such as toString and valueOf.

So neither type means "an object" in the everyday sense. For that, the lowercase object type is the right choice. Object and {} are mostly seen in old code, in generic constraints, and in lint rules that tell you to stop using them.

TypeScript
let a: {} = "text";      // allowed
let b: Object = 42;      // allowed
let c: object = {};      // fine
// let d: {} = null;     // error under strictNullChecks

Try it

TypeScript Primitives satisfy Object and {}

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

TypeScript null and undefined are rejected

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

Syntax

TypeScript
let x: Object;
let y: {};
function f<T extends {}>(v: T): T { return v; }
Type Accepts Rejects
{} Every value except null and undefined. null, undefined (with strictNullChecks).
Object Every value except null and undefined, typed with the members of Object.prototype. null, undefined (with strictNullChecks).
object Only non-primitive values. All primitives, null, undefined.

Edge cases:

  • With strictNullChecks off, null and undefined are assignable to both.
  • A value of type {} has no known properties, so you cannot read value.name without narrowing first.
  • An object literal type with members, such as { id: number }, is a different, much more useful type; only the empty literal {} is special.

Usage notes

  • Avoid them as annotations. They hide mistakes: let x: {} = "hello" compiles but the name suggests an object. Use object, unknown, Record<string, unknown> or a real interface.
  • {} in generics. T extends {} means "any non-nullish value". Before TypeScript 4.8 the unconstrained T meant {}-ish; today an unconstrained T includes null and undefined.
  • NonNullable<T>. This utility is defined as T & {}, which removes null and undefined from a union.
  • Intersections. {} is the identity for object intersections: A & {} is A for non-nullish A. This is used in tricks that keep literal unions from collapsing, such as "a" | "b" | (string & {}).
  • Lint rules. @typescript-eslint/no-empty-object-type and no-wrapper-object-types flag these types for good reasons.
  • Prefer unknown for "anything". unknown also covers null and undefined, and forces you to narrow before use.