NonExhaustiveError ts-pattern
The runtime error thrown by .exhaustive() when a value reaches it that no pattern matched.
When this matters
.exhaustive() is checked at compile time by TypeScript — if your patterns cover the input type, the call type-checks and the runtime branch is unreachable in well-typed code. NonExhaustiveError is the safety net for two cases:
- Type assertion holes — a value typed as
Tthat's actually something else at runtime (deserialization, external APIs). - Use with
any— if you opt out of exhaustiveness checking by passing throughany, the runtime check still fires.
Treat a NonExhaustiveError in production as a type-safety bug: somewhere upstream, the value is wider than its declared type.
See also
Source: ts-pattern
Re-exported unchanged from ts-pattern at the pinned version.