• P.select() is a pattern which will always match, and will inject the selected piece of input in the handler function.

    Read the documentation for P.select on GitHub

    Returns Chainable<AnonymousSelectP, "select" | "or" | "and">

    Example

    match<{ age: number }>(value)
    .with({ age: P.select() }, (age) => 'age: number'
    )
  • Type Parameters

    • input
    • const patternOrKey extends undefined | null | string | number | bigint | boolean | symbol | readonly [] | readonly [unknown, unknown] | readonly [unknown, unknown] | {
          [k: string]: unknown;
      } | UnknownMatcher | readonly UnknownPattern[] | readonly [UnknownPattern, UnknownPattern] | readonly [UnknownPattern, UnknownPattern] | PatternMatcher<input> | {
          readonly [k in string | number | symbol]?: Pattern<Readonly<MergeUnion<Exclude<input, readonly any[] | Primitives | Map<any, any> | Set<any>>>>[k]>
      }

    Parameters

    Returns patternOrKey extends string
        ? Chainable<SelectP<patternOrKey, "select" | "or" | "and">>
        : Chainable<SelectP<symbols.anonymousSelectKey, input, patternOrKey>, "select" | "or" | "and">

  • Type Parameters

    • input
    • const pattern extends undefined | null | string | number | bigint | boolean | symbol | readonly [] | readonly [unknown, unknown] | readonly [unknown, unknown] | {
          [k: string]: unknown;
      } | UnknownMatcher | readonly UnknownPattern[] | readonly [UnknownPattern, UnknownPattern] | readonly [UnknownPattern, UnknownPattern] | PatternMatcher<input> | {
          readonly [k in string | number | symbol]?: Pattern<Readonly<MergeUnion<Exclude<input, readonly any[] | Primitives | Map<any, any> | Set<any>>>>[k]>
      }
    • const k extends string

    Parameters

    Returns Chainable<SelectP<k, input, pattern>, "select" | "or" | "and">