The matched result or default value
type Status = 'draft' | 'review' | 'published';
const status: Status = 'draft';
const message = match<
Status,
{ draft: string; review: string; published: string }
>(status, {
draft: 'Work in progress',
review: 'Awaiting feedback',
published: 'Complete',
});
assert(message === 'Work in progress');
Type-safe pattern matching function for string-based discriminated unions.
Provides compile-time guarantees for exhaustive case handling when working with literal string unions. Automatically enforces completeness checking when all cases are covered, and requires a default value when cases are incomplete.
The matched result or default value
type Status = 'draft' | 'review' | 'published';
const status: Status = 'draft';
const message = match<
Status,
{ draft: string; review: string; published: string }
>(status, {
draft: 'Work in progress',
review: 'Awaiting feedback',
published: 'Complete',
});
assert(message === 'Work in progress');
Type-safe pattern matching function for string-based discriminated unions.
Provides compile-time guarantees for exhaustive case handling when working with literal string unions. Automatically enforces completeness checking when all cases are covered, and requires a default value when cases are incomplete.
Key Features: