Interface vs Type Alias in TypeScript
What is the difference between an `interface` and a `type` alias in TypeScript, and when would you choose one over the other?
what they're testing: The interviewer is checking whether you can model data clearly and choose a construct based on composition and extensibility rather than habit.
For a plain object shape, interface and type are usually interchangeable. interface User { name: string } and type User = { name: string } express the same structural requirement. Neither declaration creates a runtime value or validates data at runtime.
A type alias can name any type, including a union, primitive, tuple, or object type. An interface names an object type. Both can compose object shapes: an interface commonly uses extends, while a type alias can use an intersection such as A & B. An interface cannot extend a type with a conflicting property. Same-name interface declarations also fail when non-function properties conflict. By contrast, an intersection may compile while reducing an incompatible property to never.
Interfaces are open to declaration merging. Separate declarations with the same name combine when their members are compatible, while redeclaring a type alias is an error. That makes an interface a natural choice when consumers are meant to augment a public shape. Use a type alias for unions and other types an interface cannot name. For an ordinary object shape that does not need merging, either is reasonable, so following the codebase convention is usually the clearest choice.
Where people slip
the tempting wrong answer, and what's actually true
Interfaces and type aliases are interchangeable everywhere.
They overlap for object shapes, but only a type alias can directly name unions, primitives, tuples, and other non-object types.
Type aliases cannot be extended or composed.
Type aliases can compose object types with intersections such as `A & B`; they do not use interface declaration merging.
Interfaces and type aliases both support declaration merging.
Compatible interface declarations can merge, but redeclaring a type alias produces a duplicate identifier error.
Using a type alias instead of an interface changes the JavaScript emitted at runtime.
Both declarations belong to TypeScript's type system and do not create runtime values.
If they push further
When is declaration merging actually useful?
It is useful when an API intentionally allows consumers to augment an existing shape, especially in declaration files; otherwise a closed type alias can make ownership clearer.
How do `extends` and intersections handle conflicting properties?
An interface cannot extend a type with an incompatible same-named property. An intersection may compile but require the property to satisfy both types, which can reduce it to `never`.
Does either construct validate data at runtime?
No; both are compile-time types, so external input still needs runtime validation before the program trusts it.
Sources
- TypeScript: Everyday Types ↗typescriptlang.org
- TypeScript: Object Types ↗typescriptlang.org
- TypeScript: Declaration Merging ↗typescriptlang.org
- TypeScript for the New Programmer ↗typescriptlang.org
Now answer it yourself.
Reading a strong answer is easy. Producing one under pressure is the skill the interview tests. Gapmap grades your answer against the same bar an interviewer would.
beta
The interviewer part is in the works.
The diagnostic, personal maps, and AI mock interviews are being finished right now. The notes stay free either way. Leave an email and you'll get the first-cohort invite, plus a month of Pro when it opens.