Type vs Interface Choice
Question
When should you prefer type over interface?
Hint
Use interface for extendable objects; type for everything else.
Explanation
Prefer type alias when: 1) Defining unions (type Result = T | Error). 2) Defining tuples (type Pair = [string, number]). 3) Aliasing primitives (type ID = string). 4) Computed/conditional/mapped types. 5) When you need self-referential types. Prefer interface when: 1) Defining object shapes that may be extended (declaration merging). 2) When classes implement them. 3) For public API type definitions. The practical difference is small — use whichever reads better. Consistency within a project matters more than the choice itself.
Related Resources
Related Lessons
- Type Aliases
Learn type aliases.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.