@ossedb/patmat - v1.0.0
    Preparing search index...

    Type Alias Adt<Name, Spec>

    Adt: { readonly [K in keyof Spec & string]: CaseCtor<K, Spec[K]> } & {
        name: Name;
        is(value: unknown): value is SpecToUnion<Spec>;
        match<R>(value: SpecToUnion<Spec>, cases: Cases<SpecToUnion<Spec>, R>): R;
        match<R>(
            value: SpecToUnion<Spec>,
            cases: Partial<Cases<SpecToUnion<Spec>, R>> & {
                _: (value: SpecToUnion<Spec>) => R;
            },
        ): R;
    }

    The object returned by adt: one constructor (or singleton, for nullary cases) per case, plus name, is and an exhaustive match.

    Type Parameters

    • Name extends string
    • Spec extends Record<string, CaseSpec>

    Type Declaration

    • Readonlyname: Name

      The ADT's name, as passed to adt.

    • is: function
      • Type guard for instances of this ADT (any case).

        Parameters

        • value: unknown

        Returns value is SpecToUnion<Spec>

    • match: function
      • Matches a value against one handler per case. Omitting a case is a compile-time error — this is the statically exhaustive form.

        Type Parameters

        • R

        Parameters

        • value: SpecToUnion<Spec>
        • cases: Cases<SpecToUnion<Spec>, R>

        Returns R

      • Partial form: any subset of cases plus a _ fallback handler.

        Type Parameters

        • R

        Parameters

        • value: SpecToUnion<Spec>
        • cases: Partial<Cases<SpecToUnion<Spec>, R>> & { _: (value: SpecToUnion<Spec>) => R }

        Returns R