What is 'Discriminated Unions' and exhaustive checking?

Updated May 4, 2026

Short answer

It uses the 'never' type to ensure every member of a union is handled in a switch/if statement.

Deep explanation

By assigning the remaining variable to never in a default case, the compiler throws an error if any part of the union is unhandled. This ensures 100% code coverage for complex logic[cite: 1].

Unlock with a Pro subscription to view this section.

View pricing

Real-world example

No real-world example available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Common mistakes

No common mistakes listed yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Follow-up questions

No follow-up questions available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

More TypeScript interview questions

View all →