Skip to content
Tutorials Center
My learning

Topics

TypeScript Reference ยท Primitive and Special Types

The object type in TypeScript

Learn the lowercase object type in TypeScript: what values it accepts, what it rejects, and why it is rarely the right choice compared with real shapes.

The lowercase object type means "any value that is not a primitive". Objects, arrays, functions, class instances, Maps and Dates all qualify. Strings, numbers, booleans, bigint, symbol, null and undefined do not.

It is easy to confuse with Object (capital O) and {}, which behave differently; see Object and {}. The key point of lowercase object is that it says almost nothing about the value. You cannot read any property from it, so it is mostly useful as a constraint or a parameter type for functions that treat their argument as an opaque reference.

TypeScript
let thing: object = { id: 1 };
thing = [1, 2, 3];
thing = () => 42;

Try it

TypeScript What object accepts

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 Using object as a constraint

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;
function f(o: object): void {}
function g<T extends object>(o: T): T { return o; }
Part Description
object Any value of a non-primitive type.
Allowed Plain objects, arrays, functions, classes, instances, Map, Set, Date, RegExp and so on.
Rejected string, number, boolean, bigint, symbol, null, undefined.

Edge cases:

  • null is rejected when strictNullChecks is on (part of strict).
  • An object literal assigned to a variable of type object loses its property types for reads; use a real type or satisfies if you need them.
  • Because object has no known members, only members every object has (through Object.prototype, such as toString) are accessible.

Usage notes

  • Prefer specific types. If you know the shape, use an interface or object type. If you do not know the shape, unknown plus narrowing is usually safer than object.
  • Good uses. WeakMap<object, V> and WeakSet<object> keys, Object.keys-style helpers, and T extends object to exclude primitives from a generic.
  • Not the same as Record<string, unknown>. An object can be an array or function. Record<string, unknown> describes things you can index by string.
  • Arrays and functions count. If you want to exclude them, narrow with Array.isArray and typeof v === "function".
  • Narrowing from unknown. typeof v === "object" && v !== null narrows to object, because typeof null is "object" in JavaScript.
  • Do not confuse with the Object constructor. The value Object has methods like Object.keys; the type Object is a different thing.