TypeScript theorytheory 0/50 · 0%
Types · easy

5. Type aliases vs interfaces

Two ways to name a type, with overlapping but distinct powers.

`type` creates a named alias for any type — object shapes, unions, tuples, primitives. `interface` is specifically for object shapes but can be extended and merged.

ts
type Address = string;
type TxStatus = "pending" | "confirmed" | "failed";

interface Token {
  symbol: string;
  decimals: number;
}
interface Token {
  totalSupply: number; // declaration merging
}

Interfaces support `extends` for inheritance; type aliases use intersections (`&`) to combine shapes. In practice: use `interface` for public object APIs you may extend, and `type` for unions, tuples, and utility compositions.

Check your understanding

  1. 1. Which can represent a union type like `"pending" | "confirmed"`?

  2. 2. What is 'declaration merging'?

  3. 3. How do type aliases combine two object shapes?