SpinTheMic
Pro

Interview practice question

Ensuring every case of a union is handled

Frontend Engineering · TypeScript · Intermediate

When a new status value was added to a union, some switch statements silently didn't handle it. How do you prevent this?

What a strong answer covers

Your AI report card counts how many of these ideas you cover.

  • Exhaustiveness check with never.
  • default: const _exhaustive: never = value.
  • Compile error when case missing.
  • Lint rule (switch-exhaustiveness-check).
  • Use discriminated unions.
Practise this topic

Start without signing up. Sign in free to get an AI report card on your answer.

See all topics