Lesson 11 / 28

Type Aliases vs Interfaces

Compare type aliases and interfaces, including extends, intersections and declaration merging, and pick the right one.

Type aliases

type gives a name to any type — objects, unions, tuples, primitives.

type Point = { x: number; y: number };
type Id = string | number;

const origin: Point = { x: 0, y: 0 };

extends vs &

Interfaces combine with extends and can be re-opened later (declaration merging). Type aliases combine with & (intersection) and can't be reopened once declared.

Which to pick

Default to interface for object shapes (especially public APIs); reach for type when you need unions, tuples or computed types.

Quick check: Which of these can name a union type like `string | number`?

  • interface only
  • type only
  • Neither
  • `enum` only
Answer

type only — Interfaces can only describe object shapes; unions need a `type` alias.