Lesson 10 / 26

Type Aliases vs Interfaces

Two ways to name a type, with small but real differences.

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
Answer

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