Reference: StackOverflow Discussion
Summary
Use interface for public API definitions and when you need to take advantage of declaration merging.
Use type for unions, intersections, primitives, tuples, and general functional composition.
Key Differences
1. Declaration Merging (Interfaces only)
Interfaces strictly merge if defined multiple times. Types throw an error.
interface Window {
title: string;
}
interface Window {
ts: TypeScriptAPI;
}
// Window now has both title and ts
2. Unions & Intersections (Types are flexible)
Types can represent unions (A | B) and intersections (A & B) more naturally.
type ID = string | number;
Mental Model
- Interface: Describes the “shape” of an object (OOP style).
- Type: Describes a set of data (Functional style).