Command Palette

Search for a command to run...

Hectal
Phase 10: Utility Types and Type-Level Patterns
TypeScript · Exercise 4 of 5 PreviousNext
Advanced

Make the Bad Shipment Impossible

A Shipment is packed, shipped (it has a trackingId) or delivered (it has deliveredAt, a number). The starter type has optional fields, so { status: "packed", trackingId: "T1" } and { status: "shipped" } are both accepted.

Replace Shipment with a discriminated union so those are errors, and finish describe with a never check so a new status can't be forgotten.

What Check tests

  1. Your code has no type errors
  2. The console prints both lines
  3. A packed shipment is accepted
  4. A shipped shipment needs a tracking id
  5. A packed shipment can't have a tracking id
  6. describe ends with a never check

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Console

Nothing printed yet.