Shaping data
Interfaces and object types, type aliases, unions and intersections, and narrowing a union down to one type.
About 5 hours of study
Learning objectives
- Describe objects with interfaces
- Build discriminated unions
- Narrow unions and check exhaustiveness
Lessons
- 1
Object types and interfaces Intermediate
Describing objects with interfaces and object types: optional and readonly properties, index signatures, nested shapes, structural typing and the check for extra properties.
- 2
Type aliases, unions and intersections Intermediate
Naming types with type aliases, combining them with unions (one of several) and intersections (all at once), unions of literal values, and discriminated unions.
- 3
Narrowing: from a union to one type Intermediate
How checks narrow a union to one of its members: typeof, equality, truthiness, instanceof, in, discriminants, exhaustive switches with never, and your own type guards.
Module practice
- TypeScript: Contact cardsEasy
- TypeScript: Stock with an index signatureMedium
- TypeScript: Apply profile updatesHard
- TypeScript: Traffic light statesEasy
- TypeScript: Areas of a union of shapesMedium
- TypeScript: Process a log of typed eventsHard
- TypeScript: Describe parsed valuesEasy
- TypeScript: Validate users with a type guardMedium
- TypeScript: A robot with exhaustive commandsHard