effect-io-ai

Package: effect
Module: Match

Match.exhaustive

Completes a matcher that handles every remaining input case.

When to use

Use to require TypeScript to reject incomplete matcher definitions before the matcher is turned into a function.

Details

If any case is still unmatched, the matcher does not type-check as exhaustive.

Example (Ensuring all cases are covered)

import { Match } from "effect"

// Create a matcher for string or number values
const match = Match.type<string | number>().pipe(
  // Match when the value is a number
  Match.when(Match.number, (n) => `number: ${n}`),
  // Mark the match as exhaustive, ensuring all cases are handled
  // TypeScript will throw an error if any case is missing
  // @ts-expect-error Type 'string' is not assignable to type 'never'
  Match.exhaustive
)

Signature

declare const exhaustive: <I, F, A, Pr, Ret>(self: Matcher<I, F, never, A, Pr, Ret>) => [Pr] extends [never] ? (u: I) => Unify<A> : Unify<A>

Source

Since v4.0.0