TypeScript for Real Projects · 30 min · 220 XP

Checkpoint: shipment decisions

Design a shipment union from a brief and derive a decision without optional-property guessing.

Checkpoint: start from the brief, without copying the payment solution. First list the fields that exist in each state. Predict what the compiler should reject, then implement the behavior.

An object with status plus several optional fields allows invalid combinations: delivered with no recipient, or queued with a tracking number. A union ties each state's fields together. Keep the discriminant and data on the same object so a status check gives the compiler evidence about the other fields. After every branch returns, a never assignment makes future states visible to the compiler.

Loading your workspace…