You’ve finished Modeling Data With TypeScript. Harbor Line’s crossings started as one object for every state, and they ended as a union with one member per state that the checker keeps complete.
What You Can Do Now
- Model data with named types, unions and literal types so impossible combinations can’t be written
- Narrow a union safely
- Handle
nullandundefined - Make the checker report a case that isn’t handled
From One Object to a Union per State
The old JavaScript kept every crossing in one object. A canceled crossing kept its gate, so the old board printed 11:20 Puffin to Heron Key: boarding at gate B.
You named the shapes, gave each state a literal tag, and joined them into a union:
type Crossing =
| ScheduledCrossing
| BoardingCrossing
| DelayedCrossing
| CancelledCrossing;