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

Lessons

  1. 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. 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. 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

Module quiz

1. What does ? after a property name mean?
2. What does A | B mean?
3. Which check narrows string | number to string?
4. Why is an object literal with an unknown property an error?
5. What makes a union discriminated?
6. Why assign the switch value to never in default?

‹ Types from the startClasses and enums ›