Hint
Assigning the default case to a variable of type never is TypeScript's exhaustiveness check pattern. If the union gains a new member that isn't handled, TypeScript errors because that member is not assignable to never.
// Simulate exhaustive union checking with never
// type Status = 'active' | 'inactive' | 'pending'
function getStatusLabel(status) {
switch (status) {
case 'active': return 'Active User';
case 'inactive': return 'Inactive User';
case 'pending': return 'Pending Approval';
default:
// In TypeScript: const _check: never = status
// If all cases covered, default is unreachable — _check is never
// If a new case added without handling, _check errors at compile time
return 'Unknown: ' + status;
}
}
const statuses = ['active', 'inactive', 'pending', 'banned'];
statuses.forEach(s => console.log(getStatusLabel(s)));
// At compile time, if Status = 'active' | 'inactive' | 'pending':
// The default case has status: never — TypeScript can prove it's unreachable
console.log(statuses.length);Active User Inactive User Pending Approval Unknown: banned 4
Explanation: All three defined cases are handled. "banned" falls through to default — at runtime it returns Unknown: banned. TypeScript's never type would catch this at compile time if "banned" were added to the type without a case.
Key Insight: Assigning the default case to a variable of type never is TypeScript's exhaustiveness check pattern. If the union gains a new member that isn't handled, TypeScript errors because that member is not assignable to never.