Docs
/
TypeScript
Chapter 8
08 — Type Aliases vs Interfaces
Core Concepts
- Type aliases —
type Name = ...can represent any type - Interfaces —
interface Name { }only for object shapes - Declaration merging — only interfaces can be merged
- Extends vs Intersection — interfaces
extends, types use& - Computed/mapped types — only possible with type aliases
- Performance — interfaces are slightly faster for the compiler to check
Quick Decision Guide
| Need | Use |
|---|---|
| Object shape | Either (interface slightly preferred) |
| Union type | Type alias |
| Mapped type | Type alias |
| Conditional type | Type alias |
| Declaration merging | Interface |
| Class implements | Either |
| Primitive alias | Type alias |
| Tuple | Type alias |
| Function type | Either (type alias is cleaner) |