TypeScript·Intermediate·Coding·1 min read
When should interface be chosen over type?
Short interview answer
Choose interface for object shapes meant to be part of a public, extensible contract, especially when declaration merging is useful, such as extending a third-party library's types. Choose type when the shape is a union, tuple, or the result of a mapped or conditional expression.
Example
interface ButtonProps { variant: 'solid' | 'ghost' } // object contracttype Status = 'idle' | 'loading' | 'done'; // union — needs `type`type Pair = [number, number]; // tuple — needs `type`Key takeaway
Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.