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>;

Explanation

Lookup objects complement switch + never checks: both make new union members fail loudly at compile time.

Further reading

Problem with a question

TypeScript · Senior · question 74

Test yourself

Take the TypeScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz