Skip to content

matchWithNumberOtherwise ​

matchWithNumberOtherwise() handles selected members of a number 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 matchWithNumberOtherwise<Input extends number, Matcher, Output>(
  input: Input,
  matcher: Matcher,
  otherwise: (value: UnhandledValues) => Output
): MatcherResult | Output

Curried signature ​

typescript
function matchWithNumberOtherwise<Input extends number, Matcher, Output>(
  matcher: Matcher,
  otherwise: (value: UnhandledValues) => Output
): (input: Input) => MatcherResult | Output

Parameters ​

  • input: a number literal or literal union; broad number values are rejected.
  • matcher: a partial object whose keys can only be members of input. A property may be undefined to route that case to otherwise.
  • 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 ​

Released under the MIT license.