Caffeinated Coder
Book an appointment
Lesson 08 · Core type system

Type aliases vs interfaces

TypeScript has two ways to name a type: type, which makes a type alias, and interface. Watch tsc read both in one file: an alias naming the union number | string, an interface Pet declared twice and merged, and Dog built with extends. tsc uses the shape it builds to catch a Dog with no age, then erases every type and the program prints Rex 3.

10 min8 steps5 questionsIntermediate
Fig 8 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.