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
- Your code has no type errors
- The console prints both lines
- A packed shipment is accepted
- A shipped shipment needs a tracking id
- A packed shipment can't have a tracking id
describeends with anevercheck
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.
Press Run to see the page.
Console
Nothing printed yet.