Doubter - v5.1.1-next.e4e15ab
    Preparing search index...

    Class ArrayShape<HeadShapes, RestShape>

    The shape of an array or a tuple value.

    Shape Input Type Output Type
    ArrayShape<[], null> [] []
    ArrayShape<[], Shape<A, B>> A[] B[]
    ArrayShape<​[Shape<A, B>, Shape<X, Y>], null> [A, X] [B, Y]
    ArrayShape<​[Shape<A, B>], Shape<X, Y>> [A, ...X[]] [B, ...Y[]]

    Type Parameters

    • HeadShapes extends readonly AnyShape[]

      The array of positioned element shapes.

    • RestShape extends AnyShape | null

      The shape of rest elements, or null if there are no rest elements.

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    _options: undefined | IssueOptions | Message

    The type issue options or the type issue message.

    annotations: Dict = {}

    The dictionary of shape annotations.

    headShapes: HeadShapes

    The array of positioned element shapes.

    inputs: readonly unknown[]

    The array of unique input types and values that are accepted by the shape.

    isAsync: boolean

    true if the shape allows only Shape.parseAsync and throws an error if Shape.parse is called, or false if the shape can be used in both sync and async contexts.

    isCoercing: boolean = false

    true if this shape coerces input values to the required type during parsing, or false otherwise.

    operations: readonly Operation[] = []

    The array of operations that are applied to the shape output.

    restShape: RestShape

    The shape of rest elements or null if there are no rest elements.

    Methods

    • Synchronously parses the input.

      Parameters

      • input: any

        The shape input to parse.

      • options: ParseOptions

        Parsing options.

      • nonce: number

      Returns Result<
          [
              ...{ [K in string
              | number
              | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
              ...(
                  RestShape extends undefined
                  | null
                      ? []
                      : RestShape extends Shape<any, any>
                          ? RestShape<RestShape>[typeof OUTPUT][]
                          : []
              )[],
          ],
      >

      null if input matches the output, Ok that wraps the output, or an array of captured issues.

    • Asynchronously parses the input.

      Parameters

      • input: any

        The shape input to parse.

      • options: ParseOptions

        Parsing options.

      • nonce: number

        The globally unique number that identifies the parsing process.

      Returns Promise<
          Result<
              [
                  ...{
                      [K in string
                      | number
                      | symbol]: HeadShapes[K<K>][typeof OUTPUT]
                  }[],
                  ...(
                      RestShape extends undefined
                      | null
                          ? []
                          : RestShape extends Shape<any, any>
                              ? RestShape<RestShape>[typeof OUTPUT][]
                              : []
                  )[],
              ],
          >,
      >

      null if input matches the output, Ok that wraps the output, or an array of captured issues.

    • Returns input types and literal values that this shape can accept as an input.

      Returns readonly unknown[]

    • Must return true if the shape must be used in async context only, otherwise the shape can be used in both sync and async contexts. Override this method to implement a custom shape.

      Returns boolean

    • Returns true if the shape accepts given input type or value, or false otherwise.

      Parameters

      • input: unknown

        The type or value that must be checked.

      Returns boolean

    • Adds an asynchronous operation to the shape.

      Type Parameters

      • Param

        The param that is passed to the operation when it is applied.

      Parameters

      • cb: OperationCallback<
            PromiseLike<
                Result<
                    [
                        ...{
                            [K in string
                            | number
                            | symbol]: HeadShapes[K<K>][typeof OUTPUT]
                        }[],
                        ...(
                            RestShape extends undefined
                            | null
                                ? []
                                : RestShape extends Shape<any, any>
                                    ? RestShape<RestShape>[typeof OUTPUT][]
                                    : []
                        )[],
                    ],
                >,
            >,
            [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof OUTPUT][]
                            : []
                )[],
            ],
            Param,
        >

        The callback that asynchronously applies an operation to the shape output value.

      • Optionaloptions: ParameterizedOperationOptions<Param>

        The operation options.

      Returns this

      The clone of the shape.

    • Adds an asynchronous operation to the shape.

      Parameters

      • cb: OperationCallback<
            PromiseLike<
                Result<
                    [
                        ...{
                            [K in string
                            | number
                            | symbol]: HeadShapes[K<K>][typeof OUTPUT]
                        }[],
                        ...(
                            RestShape extends undefined
                            | null
                                ? []
                                : RestShape extends Shape<any, any>
                                    ? RestShape<RestShape>[typeof OUTPUT][]
                                    : []
                        )[],
                    ],
                >,
            >,
            [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof OUTPUT][]
                            : []
                )[],
            ],
        >

        The callback that asynchronously applies an operation to the shape output value.

      • Optionaloptions: OperationOptions

        The operation options.

      Returns this

      The clone of the shape.

    • Adds a synchronous operation to the shape.

      Type Parameters

      • Param

        The param that is passed to the operation when it is applied.

      Parameters

      • cb: OperationCallback<
            Result<
                [
                    ...{
                        [K in string
                        | number
                        | symbol]: HeadShapes[K<K>][typeof OUTPUT]
                    }[],
                    ...(
                        RestShape extends undefined
                        | null
                            ? []
                            : RestShape extends Shape<any, any>
                                ? RestShape<RestShape>[typeof OUTPUT][]
                                : []
                    )[],
                ],
            >,
            [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof OUTPUT][]
                            : []
                )[],
            ],
            Param,
        >

        The callback that synchronously applies an operation to the shape output value.

      • Optionaloptions: ParameterizedOperationOptions<Param>

        The operation options.

      Returns this

      The clone of the shape.

    • Adds a synchronous operation to the shape.

      Parameters

      • cb: OperationCallback<
            Result<
                [
                    ...{
                        [K in string
                        | number
                        | symbol]: HeadShapes[K<K>][typeof OUTPUT]
                    }[],
                    ...(
                        RestShape extends undefined
                        | null
                            ? []
                            : RestShape extends Shape<any, any>
                                ? RestShape<RestShape>[typeof OUTPUT][]
                                : []
                    )[],
                ],
            >,
            [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof OUTPUT][]
                            : []
                )[],
            ],
        >

        The callback that synchronously applies an operation to the shape output value.

      • Optionaloptions: OperationOptions

        The operation options.

      Returns this

      The clone of the shape.

    • Adds a synchronous operation that alters the output value without changing its type.

      If you want to change the base type, consider using Shape.convert.

      Type Parameters

      • Param

        The param that is passed to the operation when it is applied.

      Parameters

      • cb: OperationCallback<
            [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof OUTPUT][]
                            : []
                )[],
            ],
            [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof OUTPUT][]
                            : []
                )[],
            ],
            Param,
        >

        The callback that alters the shape output. Throw a ValidationError to notify that the alteration cannot be successfully completed.

      • options: ParameterizedOperationOptions<Param>

        The operation options.

      Returns this

      The clone of the shape.

    • Adds a synchronous operation that alters the output value without changing its type.

      If you want to change the base type, consider using Shape.convert.

      Parameters

      • cb: OperationCallback<
            [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof OUTPUT][]
                            : []
                )[],
            ],
            [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof OUTPUT][]
                            : []
                )[],
            ],
        >

        The callback that alters the shape output. Throw a ValidationError to notify that the alteration cannot be successfully completed.

      • Optionaloptions: OperationOptions

        The operation options.

      Returns this

      The clone of the shape.

    • Adds an asynchronous operation that alters the output value without changing its type.

      If you want to change the base type, consider using Shape.convertAsync.

      Type Parameters

      • Param

        The param that is passed to the operation when it is applied.

      Parameters

      • cb: OperationCallback<
            PromiseLike<
                [
                    ...{
                        [K in string
                        | number
                        | symbol]: HeadShapes[K<K>][typeof OUTPUT]
                    }[],
                    ...(
                        RestShape extends undefined
                        | null
                            ? []
                            : RestShape extends Shape<any, any>
                                ? RestShape<RestShape>[typeof OUTPUT][]
                                : []
                    )[],
                ],
            >,
            [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof OUTPUT][]
                            : []
                )[],
            ],
            Param,
        >

        The callback that alters the shape output. Throw a ValidationError to notify that the alteration cannot be successfully completed.

      • options: ParameterizedOperationOptions<Param>

        The operation options.

      Returns this

      The clone of the shape.

    • Adds an asynchronous operation that alters the output value without changing its type.

      If you want to change the base type, consider using Shape.convertAsync.

      Parameters

      • cb: OperationCallback<
            PromiseLike<
                [
                    ...{
                        [K in string
                        | number
                        | symbol]: HeadShapes[K<K>][typeof OUTPUT]
                    }[],
                    ...(
                        RestShape extends undefined
                        | null
                            ? []
                            : RestShape extends Shape<any, any>
                                ? RestShape<RestShape>[typeof OUTPUT][]
                                : []
                    )[],
                ],
            >,
            [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof OUTPUT][]
                            : []
                )[],
            ],
        >

        The callback that alters the shape output. Throw a ValidationError to notify that the alteration cannot be successfully completed.

      • Optionaloptions: OperationOptions

        The operation options.

      Returns this

      The clone of the shape.

    • Adds annotations to the shape.

      Parameters

      • annotations: ReadonlyDict

        Annotations to add.

      Returns this

      The clone of the shape with the updated annotations.

    • Returns a sub-shape that describes a value associated with the given property name, or null if there's no such sub-shape.

      Parameters

      • key: unknown

      Returns null | AnyShape

      The sub-shape or null if there's no such key in the shape.

    • Returns a shape that adds a brand to the output type.

      Type Parameters

      • Brand extends string | number | symbol

        The brand value.

      Returns RefineShape<
          ArrayShape<HeadShapes, RestShape>,
          Branded<
              [
                  ...{
                      [K in string
                      | number
                      | symbol]: HeadShapes[K<K>][typeof OUTPUT]
                  }[],
                  ...(
                      RestShape extends undefined
                      | null
                          ? []
                          : RestShape extends Shape<any, any>
                              ? RestShape<RestShape>[typeof OUTPUT][]
                              : []
                  )[],
              ],
              Brand,
          >,
      >

      A shape with the branded output type.

    • Adds a synchronous operation that checks that the shape output satisfies a requirement.

      The callback must return null or undefined if value is valid, or an issue or an array of issues if value is invalid. If a callback returns an empty array, it is considered that no issues have occurred.

      Type Parameters

      • Param

        The param that is passed to the operation when it is applied.

      Parameters

      • cb: OperationCallback<
            CheckResult,
            [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof OUTPUT][]
                            : []
                )[],
            ],
            Param,
        >

        The callback that checks that a value satisfies a requirement and returns issues if it doesn't.

      • options: ParameterizedOperationOptions<Param>

        The operation options.

      Returns this

      The clone of the shape.

    • Adds a synchronous operation that checks that the shape output satisfies a requirement.

      The callback must return null or undefined if value is valid, or an issue or an array of issues if value is invalid. If a callback returns an empty array, it is considered that no issues have occurred.

      Parameters

      • cb: OperationCallback<
            CheckResult,
            [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof OUTPUT][]
                            : []
                )[],
            ],
        >

        The callback that checks that a value satisfies a requirement and returns issues if it doesn't.

      • Optionaloptions: OperationOptions

        The operation options.

      Returns this

      The clone of the shape.

    • Adds an asynchronous operation that checks that the shape output satisfies a requirement.

      The callback must return a promise that is resolved with null or undefined if value is valid, or an issue or an array of issues if value is invalid. If promise resolves with an empty array, it is considered that no issues have occurred.

      Type Parameters

      • Param

        The param that is passed to the operation when it is applied.

      Parameters

      • cb: OperationCallback<
            PromiseLike<CheckResult>,
            [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof OUTPUT][]
                            : []
                )[],
            ],
            Param,
        >

        The callback that checks that a value satisfies a requirement and returns issues if it doesn't.

      • options: ParameterizedOperationOptions<Param>

        The operation options.

      Returns this

      The clone of the shape.

    • Adds an asynchronous operation that checks that the shape output satisfies a requirement.

      The callback must return a promise that is resolved with null or undefined if value is valid, or an issue or an array of issues if value is invalid. If promise resolves with an empty array, it is considered that no issues have occurred.

      Parameters

      • cb: OperationCallback<
            PromiseLike<CheckResult>,
            [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof OUTPUT][]
                            : []
                )[],
            ],
        >

        The callback that checks that a value satisfies a requirement and returns issues if it doesn't.

      • Optionaloptions: OperationOptions

        The operation options.

      Returns this

      The clone of the shape.

    • Enables an input value coercion.

      Returns this

      The clone of the shape.

    • Synchronously converts the output value of the shape.

      If you want to don't want to change the base type, consider using Shape.alter.

      Type Parameters

      • ConvertedValue

        The value returned from the callback that converts the output value of this shape.

      Parameters

      • cb: (
            value: [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof OUTPUT][]
                            : []
                )[],
            ],
            options: ParseOptions,
        ) => ConvertedValue

        The callback that converts the input value. Throw a ValidationError to notify that the conversion cannot be successfully completed.

      Returns Shape<
          [
              ...{ [K in string
              | number
              | symbol]: HeadShapes[K<K>][typeof INPUT] }[],
              ...(
                  RestShape extends undefined
                  | null
                      ? []
                      : RestShape extends Shape<any, any>
                          ? RestShape<RestShape>[typeof INPUT][]
                          : []
              )[],
          ],
          ConvertedValue,
      >

      The ConvertShape instance.

    • Asynchronously converts the output value of the shape.

      If you want to don't want to change the base type, consider using Shape.alterAsync.

      Type Parameters

      • ConvertedValue

        The value returned from the callback that converts the output value of this shape.

      Parameters

      • cb: (
            value: [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof OUTPUT][]
                            : []
                )[],
            ],
            options: ParseOptions,
        ) => PromiseLike<ConvertedValue>

        The callback that converts the input value asynchronously. The returned promise can be rejected with a ValidationError to notify that the conversion cannot be successfully completed.

      Returns Shape<
          [
              ...{ [K in string
              | number
              | symbol]: HeadShapes[K<K>][typeof INPUT] }[],
              ...(
                  RestShape extends undefined
                  | null
                      ? []
                      : RestShape extends Shape<any, any>
                          ? RestShape<RestShape>[typeof INPUT][]
                          : []
              )[],
          ],
          ConvertedValue,
      >

      The ConvertShape instance.

    • Excludes value from both input and output.

      Type Parameters

      • DeniedValue extends
            | [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof INPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof INPUT][]
                            : []
                )[],
            ]
            | [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof OUTPUT][]
                            : []
                )[],
            ]

        The denied value.

      Parameters

      Returns DenyShape<ArrayShape<HeadShapes, RestShape>, DeniedValue>

    • Synchronously parses the value.

      Parameters

      • input: unknown

        The value to parse.

      • Optionaloptions: ParseOptions

        Parsing options.

      Returns [
          ...{ [K in string
          | number
          | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
          ...(
              RestShape extends undefined
              | null
                  ? []
                  : RestShape extends Shape<any, any>
                      ? RestShape<RestShape>[typeof OUTPUT][]
                      : []
          )[],
      ]

      The value that conforms the output type of the shape.

      Error if the shape doesn't support the sync parsing, see Shape.isAsync.

      ValidationError if any issues occur during parsing.

    • Asynchronously parses the value.

      Parameters

      • input: unknown

        The value to parse.

      • Optionaloptions: ParseOptions

        Parsing options.

      Returns Promisify<
          [
              ...{ [K in string
              | number
              | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
              ...(
                  RestShape extends undefined
                  | null
                      ? []
                      : RestShape extends Shape<any, any>
                          ? RestShape<RestShape>[typeof OUTPUT][]
                          : []
              )[],
          ],
      >

      The promise that resolves with the value that conforms the output type of the shape, or rejects with a ValidationError if any issues occur during parsing.

    • Synchronously parses the value and returns undefined if parsing fails.

      Parameters

      • input: unknown

        The value to parse.

      Returns
          | undefined
          | [
              ...{ [K in string
              | number
              | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
              ...(
                  RestShape extends undefined
                  | null
                      ? []
                      : RestShape extends Shape<any, any>
                          ? RestShape<RestShape>[typeof OUTPUT][]
                          : []
              )[],
          ]

      The value that conforms the output type of the shape.

      Error if the shape doesn't support the sync parsing, see Shape.isAsync.

    • Synchronously parses the value and returns the default value if parsing fails.

      Type Parameters

      • DefaultValue

        The default value that is returned if parsing fails.

      Parameters

      • input: unknown

        The value to parse.

      • defaultValue: DefaultValue

        The default value that is returned if parsing fails.

      • Optionaloptions: ParseOptions

        Parsing options.

      Returns
          | [
              ...{ [K in string
              | number
              | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
              ...(
                  RestShape extends undefined
                  | null
                      ? []
                      : RestShape extends Shape<any, any>
                          ? RestShape<RestShape>[typeof OUTPUT][]
                          : []
              )[],
          ]
          | DefaultValue

      The value that conforms the output type of the shape.

      Error if the shape doesn't support the sync parsing, see Shape.isAsync.

    • Asynchronously parses the value and returns undefined value if parsing fails.

      Parameters

      • input: unknown

        The value to parse.

      Returns Promisify<
          | undefined
          | [
              ...{ [K in string
              | number
              | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
              ...(
                  RestShape extends undefined
                  | null
                      ? []
                      : RestShape extends Shape<any, any>
                          ? RestShape<RestShape>[typeof OUTPUT][]
                          : []
              )[],
          ],
      >

      The value that conforms the output type of the shape.

    • Asynchronously parses the value and returns the default value if parsing fails.

      Type Parameters

      • DefaultValue

        The default value that is returned if parsing fails.

      Parameters

      • input: unknown

        The value to parse.

      • defaultValue: DefaultValue

        The default value that is returned if parsing fails.

      • Optionaloptions: ParseOptions

        Parsing options.

      Returns Promisify<
          | [
              ...{ [K in string
              | number
              | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
              ...(
                  RestShape extends undefined
                  | null
                      ? []
                      : RestShape extends Shape<any, any>
                          ? RestShape<RestShape>[typeof OUTPUT][]
                          : []
              )[],
          ]
          | DefaultValue,
      >

      The value that conforms the output type of the shape.

    • Adds a synchronous operation that refines the shape output type with the narrowing predicate.

      Type Parameters

      • RefinedValue extends [
            ...{ [K in string
            | number
            | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
            ...(
                RestShape extends undefined
                | null
                    ? []
                    : RestShape extends Shape<any, any>
                        ? RestShape<RestShape>[typeof OUTPUT][]
                        : []
            )[],
        ]

        The narrowed output value.

      • Param

        The param that is passed to the operation when it is applied.

      Parameters

      • cb: RefinePredicate<
            [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof OUTPUT][]
                            : []
                )[],
            ],
            RefinedValue,
            Param,
        >

        The predicate that returns true if the value conforms the required type, or false otherwise.

      • options: Message | ParameterizedRefineOptions<Param>

        The operation options or the issue message.

      Returns RefineShape<ArrayShape<HeadShapes, RestShape>, RefinedValue>

      The shape with the narrowed output.

    • Adds a synchronous operation that refines the shape output type with the narrowing predicate.

      Type Parameters

      • RefinedValue extends [
            ...{ [K in string
            | number
            | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
            ...(
                RestShape extends undefined
                | null
                    ? []
                    : RestShape extends Shape<any, any>
                        ? RestShape<RestShape>[typeof OUTPUT][]
                        : []
            )[],
        ]

        The narrowed output value.

      Parameters

      • cb: RefinePredicate<
            [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof OUTPUT][]
                            : []
                )[],
            ],
            RefinedValue,
        >

        The predicate that returns true if the value conforms the required type, or false otherwise.

      • Optionaloptions: Message | RefineOptions

        The operation options or the issue message.

      Returns RefineShape<ArrayShape<HeadShapes, RestShape>, RefinedValue>

      The shape with the narrowed output.

    • Adds a synchronous operation that checks that the output value conforms the predicate.

      Type Parameters

      • Param

        The param that is passed to the operation when it is applied.

      Parameters

      • cb: OperationCallback<
            unknown,
            [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof OUTPUT][]
                            : []
                )[],
            ],
            Param,
        >

        The predicate that returns truthy result if the value is valid, or returns falsy result otherwise.

      • Optionaloptions: Message | ParameterizedRefineOptions<Param>

        The operation options or the issue message.

      Returns this

      The clone of the shape.

    • Adds a synchronous operation that checks that the output value conforms the predicate.

      Parameters

      • cb: OperationCallback<
            unknown,
            [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof OUTPUT][]
                            : []
                )[],
            ],
        >

        The predicate that returns truthy result if the value is valid, or returns falsy result otherwise.

      • Optionaloptions: Message | RefineOptions

        The operation options or the issue message.

      Returns this

      The clone of the shape.

    • Adds an asynchronous operation that checks that the output value conforms the predicate.

      Type Parameters

      • Param

        The param that is passed to the operation when it is applied.

      Parameters

      • cb: OperationCallback<
            PromiseLike<unknown>,
            [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof OUTPUT][]
                            : []
                )[],
            ],
            Param,
        >

        The predicate that returns a promise that resolves with a truthy result if the value is valid, or a falsy result otherwise.

      • Optionaloptions: Message | ParameterizedRefineOptions<Param>

        The operation options or the issue message.

      Returns this

      The clone of the shape.

    • Adds an asynchronous operation that checks that the output value conforms the predicate.

      Parameters

      • cb: OperationCallback<
            PromiseLike<unknown>,
            [
                ...{ [K in string
                | number
                | symbol]: HeadShapes[K<K>][typeof OUTPUT] }[],
                ...(
                    RestShape extends undefined
                    | null
                        ? []
                        : RestShape extends Shape<any, any>
                            ? RestShape<RestShape>[typeof OUTPUT][]
                            : []
                )[],
            ],
        >

        The predicate that returns a promise that resolves with a truthy result if the value is valid, or a falsy result otherwise.

      • Optionaloptions: Message | RefineOptions

        The operation options or the issue message.

      Returns this

      The clone of the shape.

    • Returns an array shape that has rest elements constrained by the given shape.

      Note: This method returns a shape without any operations.

      Type Parameters

      • S extends null | AnyShape

        The shape of rest elements.

      Parameters

      • restShape: S

        The shape of rest elements, or null if there are no rest elements.

      Returns ArrayShape<HeadShapes, S>

      The new array shape.

    • Synchronously parses the value and returns Ok or Err object that wraps the result.

      Parameters

      • input: unknown

        The value to parse.

      • Optionaloptions: ParseOptions

        Parsing options.

      Returns
          | Err
          | Ok<
              [
                  ...{
                      [K in string
                      | number
                      | symbol]: HeadShapes[K<K>][typeof OUTPUT]
                  }[],
                  ...(
                      RestShape extends undefined
                      | null
                          ? []
                          : RestShape extends Shape<any, any>
                              ? RestShape<RestShape>[typeof OUTPUT][]
                              : []
                  )[],
              ],
          >

      The Ok instance if parsing has succeeded or Err if parsing has failed.

      Error if the shape doesn't support the sync parsing, see Shape.isAsync.

    • Asynchronously parses the value and returns Ok or Err object that wraps the result.

      Parameters

      • input: unknown

        The value to parse.

      • Optionaloptions: ParseOptions

        Parsing options.

      Returns Promise<
          | Err
          | Ok<
              [
                  ...{
                      [K in string
                      | number
                      | symbol]: HeadShapes[K<K>][typeof OUTPUT]
                  }[],
                  ...(
                      RestShape extends undefined
                      | null
                          ? []
                          : RestShape extends Shape<any, any>
                              ? RestShape<RestShape>[typeof OUTPUT][]
                              : []
                  )[],
              ],
          >,
      >

      The Ok instance if parsing has succeeded or Err if parsing has failed.

    Plugin Methods

    • Requires an array to contain at least one element that conforms the given shape.

      Parameters

      • value: any

        The shape of the required element or its literal value.

      • Optionaloptions: IssueOptions | Message

        The issue options or the issue message.

      Returns this

      The clone of the shape.