matchWithStringOtherwise
matchWithStringOtherwise() handles selected members of a string literal union. Matcher keys must belong to the input union, but may omit cases. The otherwise callback receives only the literals that have no handler.
Interactive example
Syntax
Classic signature
typescript
function matchWithStringOtherwise<Input extends string, Matcher, Output>(
input: Input,
matcher: Matcher,
otherwise: (value: UnhandledValues) => Output
): MatcherResult | OutputCurried signature
typescript
function matchWithStringOtherwise<Input extends string, Matcher, Output>(
matcher: Matcher,
otherwise: (value: UnhandledValues) => Output
): (input: Input) => MatcherResult | OutputParameters
input: a string literal or literal union; broadstringvalues are rejected.matcher: a partial object whose keys can only be members ofinput. A property may beundefinedto route that case tootherwise.otherwise: receives the exact union of cases without a handler.
Return value
The selected handler result, or the otherwise result for an unhandled value.
See also
matchWithString- Exhaustive string matching.matchWithNumberOtherwise- Numeric partial matching.
