TypeScript · Senior · Question 74 of 75
How can you make a discriminated union exhaustive check also catch a missing case at the data layer?
const labels = { draft: 'Draft', published: 'Live' } satisfies Record<Status, string>;- ✓Correct answer: Use
satisfies Record<Union, ...>for lookup tables so adding a union member errors where the mapping is missing - 2Use
Partial<Record<...>> - 3Use a
Mapwithout types
Explanation
Lookup objects complement switch + never checks: both make new union members fail loudly at compile time.