typescript-exhaustive-switch

Enforce compile-time exhaustive switch handling for TypeScript discriminated unions and enums.

Updated May 22, 2026
One-click install
npx skills add https://github.com/paulbrittain/claude-team-kit --skill typescript-exhaustive-switch
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-exhaustive-switch
Source: https://github.com/paulbrittain/claude-team-kit/tree/main/skills/typescript-exhaustive-switch
Command: npx skills add https://github.com/paulbrittain/claude-team-kit --skill typescript-exhaustive-switch

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill prevents silent logic gaps in TypeScript by forcing switch statements over discriminated unions or enums to handle every possible variant, so newly added variants fail fast at compile time instead of causing runtime bugs.

Core Features & Use Cases

  • Exhaustive default never check: Uses the default branch to create a compile-time error when an unhandled variant appears.
  • Works for discriminated unions and enums: Ensures safety when switching over kind-style tagged unions, string literal unions, or enums.
  • Clear failure signal: Produces a type-checking failure that points developers directly to the missing case.

Quick Start

When you are editing a TypeScript switch over a discriminated union, apply an exhaustive default branch using a never-typed variable so TypeScript reports a compile error if any variant is missing.

Frequently Asked Questions about typescript-exhaustive-switch

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce exhaustive switch statements in TypeScript?

Exhaustive switch statements in TypeScript are enforced by assigning the switched value to a `never` typed variable in the default case, which triggers a compile-time error if any union member or enum value is missing.

What's the best way to catch missing cases when refactoring TypeScript discriminated unions?

The best way to catch missing cases when refactoring TypeScript discriminated unions is adding a default case that assigns the switched value to a `never` type, failing fast at compile time instead of causing runtime bugs.

Why does TypeScript not warn me about unhandled enum values in a switch statement?

TypeScript does not warn about unhandled enum values because standard switch statements lack inherent exhaustiveness checking; you must manually add a default branch assigning the value to `never` to trigger a compile-time error.

Does exhaustive switch checking work with string literal unions in TypeScript?

Yes, exhaustive switch checking works with string literal unions in TypeScript by applying the same `never` type check in the default case to ensure every possible string variant is explicitly handled during compile-time type checking.

When do I need to use the TypeScript never type for code safety?

You need to use the TypeScript `never` type for code safety when switching over discriminated unions or enums during feature development, ensuring newly added variants produce a clear compile-time failure pointing to the missing case.