Interfaces & type aliases
Try code in the playgroundUnderstand the concept
Interfaces and type aliases both describe types that TypeScript checks before runtime. An interface is mainly used for object contracts, while a type alias can name object shapes, unions, tuples and other type expressions. Choosing between them is mostly about the shape being modeled and whether declaration merging is needed.
Important ideas
-
Both can describe an object shape.
-
Interfaces can merge declarations; type aliases can also describe unions and other types.
-
Neither checks incoming API data at runtime.
-
An interface can extend another interface, and a type can combine object shapes through intersections.
-
TypeScript uses structural typing: matching members matter more than explicitly naming the same interface.
Can you explain it without the notes?
Interface vs type: which should I use?
Use your own words. Explain an example and one limitation before checking the explanation.
Check your explanation
Interfaces and type aliases both describe types that TypeScript checks before runtime. An interface is mainly used for object contracts, while a type alias can name object shapes, unions, tuples and other type expressions. Choosing between them is mostly about the shape being modeled and whether declaration merging is needed.
Turn this concept into a clear answer.
- Both improve compile-time contracts, but neither creates a runtime validator or a JavaScript class.
Adapted from 01_JAVASCRIPT_TYPESCRIPT.md · “Interface vs type: which should I use?”. Examples are study fragments; framework behavior can depend on your version.