• P.array(subpattern) takes a sub pattern and returns a pattern, which matches arrays if all their elements match the sub pattern.

    Read the documentation for P.array on GitHub

    Type Parameters

    • input

    Returns ArrayChainable<ArrayP<input, unknown>>

    Example

    match(value)
    .with({ users: P.array({ name: P.string }) }, () => 'will match { name: string }[]')
  • Type Parameters

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

    Parameters

    Returns ArrayChainable<ArrayP<input, pattern>>