• P.shape(somePattern) lets you call methods like .optional(), .and, .or and .select() On structural patterns, like objects and arrays.

    Read the documentation for P.shape on GitHub

    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]>
      }

    Parameters

    Returns Chainable<GuardP<input, InvertPattern<pattern, input>>>

    Example

    .with(
    {
    state: P.shape({ status: "success" }).optional().select()
    },
    (state) => 'match the success state, or undefined.'
    )