Q10. What is the difference between interface and type?
Both can describe object shapes. Interfaces support declaration merging and extension; type aliases can name unions, tuples, primitives, intersections, and other type expressions. For ordinary object contracts, either may work, so choose based on intent and project conventions.
Use an interface for an extendable object contract if that suits the API; use a type alias for unions such as status variants.
Note
Interview approach: define the concept, explain why it matters, then mention one trade-off or limitation.
Type alias union
type Status = "idle" | "loading" | "done";💡 A type alias can name union types that interfaces cannot directly represent.
Key Takeaways
- Explain the concept in your own words.
- Know the practical trade-off and its limits.
- Use a small example to demonstrate the idea.
Knowledge Check
Which construct naturally names a union like `"on" | "off"`?