onrails
    Preparing search index...

    Class MatchBuilder<T, R, HasInput, Handled, Locked>

    Fluent builder for match. Tracks the handled cases at the type level so .exhaustive() only compiles when every union member is covered.

    The Locked phantom flag (set via .returnType<R>()) constrains every subsequent handler to return R, useful when branch return-type inference would widen to a union narrower than the target slot (e.g. ReactNode, an API DTO).

    const describe = match<Event>()
    .with({ kind: "click" }, (e) => `click @ ${e.x},${e.y}`)
    .with({ kind: "key" }, (e) => `key ${e.code}`)
    .exhaustive();

    Type Parameters

    • T
    • R = never
    • HasInput extends boolean = false
    • Handled extends readonly unknown[] = []
    • Locked extends boolean = false
    Index

    Constructors

    Properties

    _handled: Handled = ...

    Methods

    • Run on the value passed to match, or on input when curried.

      Parameters

      • Optionalinput: T

      Returns R