What is the difference between type and interface in TypeScript?

Why Interviewers Ask This

This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex TypeScript topics. It also reveals how well you can explain technical ideas to non-experts.

Answer

While type and interface overlap significantly for object types, their differences matter in practice. Similarities: both can describe object shapes, be extended/combined, and are erased at runtime. Differences: (1) Declaration merging — interfaces with the same name are automatically merged; type aliases cannot be re-declared. (2) What they can describe — type aliases can describe any type (unions, intersections, primitives, tuples, functions); interfaces can only describe object/class shapes and function signatures. (3) Extension syntax — interfaces use extends; type aliases use & for intersection. (4) Error messages — interfaces often produce more readable error messages in the compiler output. (5) Performance — interfaces are generally faster to check in complex codebases because TypeScript caches them. Community consensus: use interface for object shapes in public APIs; use type for unions, intersections, mapped types, and when you need the flexibility of a type alias.

Pro Tip

Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex TypeScript answers easy to follow.