onrails
    Preparing search index...

    Type Alias Pattern<T>

    Pattern: T | ObjectPattern<T> | PatternGuard<T>

    A pattern that matches a value of type T. One of:

    • Literal — a primitive ("a", 42, true) matched by ===.
    • Object pattern — a Partial<T> of shallow key/value pairs that must all match by strict equality. Only available when T is an object type.
    • Guard — a function (input: T) => boolean. Type predicates ((x): x is U) narrow the handler input via Narrow.

    Type Parameters

    • T
    type Event = { kind: "click"; x: number } | { kind: "key"; code: string };

    const p1: Pattern<Event> = { kind: "click" }; // object pattern
    const p2: Pattern<Event> = (e) => e.kind === "key"; // guard