Class ObjectShape<PropShapes, RestShape>

The shape of an object.

Type Parameters

  • PropShapes extends ReadonlyDict<AnyShape>

    The mapping from a string object key to a corresponding value shape.

  • RestShape extends AnyShape | null

    The shape that constrains values of a string index signature, or null if there's no index signature.

Hierarchy

  • Shape<InferObject<PropShapes, RestShape, INPUT>, InferObject<PropShapes, RestShape, OUTPUT>>
    • ObjectShape

Implements

Constructors

  • Creates a new ObjectShape instance.

    Type Parameters

    Parameters

    • propShapes: PropShapes

      The mapping from an object key to a corresponding value shape.

    • restShape: RestShape

      The shape that constrains values of a string index signature. If null then values thea fall under the index signature are unconstrained.

    • Optional options: IssueOptions | Message

      The issue options or the issue message.

    • keysMode: ObjectKeysMode = 'preserved'

      The mode of keys handling.

    Returns ObjectShape<PropShapes, RestShape>

Properties

_applyOperations: ApplyOperationsCallback

The callback that applies Shape.operations to the shape output value.

This method returns a promise if there are async Shape.operations.

If the shape overrides only Shape._apply and doesn't override Shape._applyAsync then it's only safe to call this method as the last statement in Shape._apply. Otherwise, it may return an unexpected promise.

If the shape overrides both Shape._apply and Shape._applyAsync then this method would always synchronously return a Result inside Shape._apply.

_exactIssueFactory?: ((input, options, param) => Issue)

Type declaration

    • (input, options, param): Issue
    • Returns issues which describe that an object has unknown properties.

      Parameters

      Returns Issue

_options: undefined | IssueOptions | Message

The issue options or the issue message.

_typeIssueFactory: ((input, options) => Issue)

Type declaration

    • (input, options): Issue
    • Returns issues associated with an invalid input value type.

      Parameters

      Returns Issue

annotations: Dict<any> = {}

The dictionary of shape annotations.

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.

keys: readonly string[]

The array of known object keys.

keysMode: ObjectKeysMode = 'preserved'

The mode of unknown keys handling.

  • If preserved then unknown object keys are preserved as-is or checked with ObjectShape.restShape.
  • If stripped then the input object is cloned and unknown keys are removed from it.
  • If exact then an issue is raised if an unknown key is met.

Default

'preserved'
operations: readonly Operation[] = []

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

propShapes: PropShapes

The mapping from an object key to a corresponding value shape.

restShape: RestShape

The shape that constrains values of a string index signature.

valueShapes: readonly Shape<any, any>[]

The array of property shapes, parallel to ObjectShape.keys.

messages: Messages = defaultMessages

The mapping from an issue type to a corresponding issue message.

Methods

  • Synchronously parses the input.

    Parameters

    • input: any

      The shape input to parse.

    • options: ApplyOptions

      Parsing options.

    • nonce: number

      The globally unique number that identifies the parsing process.

    Returns Result<{
        [K in string | number | symbol]: (Omit<{
            [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
        }, OptionalKeys<{
            [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
        }>> & {
            [K in string | number | symbol]?: {
                [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
            }[K]
        } & (RestShape extends undefined | null
            ? {}
            : RestShape extends Shape<any, any>
                ? {
                    [key: string]: RestShape[Leg];
                }
                : {}))[K]
    }>

    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: ApplyOptions

      Parsing options.

    • nonce: number

      The globally unique number that identifies the parsing process.

    Returns Promise<Result<{
        [K in string | number | symbol]: (Omit<{
            [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
        }, OptionalKeys<{
            [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
        }>> & {
            [K in string | number | symbol]?: {
                [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
            }[K]
        } & (RestShape extends undefined | null
            ? {}
            : RestShape extends Shape<any, any>
                ? {
                    [key: string]: RestShape[Leg];
                }
                : {}))[K]
    }>>

    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]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }>>, {
          [K in string | number | symbol]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }, Param>

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

    • Optional options: ParameterizedOperationOptions<Param>

      The operation options.

    Returns ObjectShape<PropShapes, RestShape>

    The clone of the shape.

  • Adds an asynchronous operation to the shape.

    Parameters

    • cb: OperationCallback<PromiseLike<Result<{
          [K in string | number | symbol]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }>>, {
          [K in string | number | symbol]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }>

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

    • Optional options: OperationOptions

      The operation options.

    Returns ObjectShape<PropShapes, RestShape>

    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]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }>, {
          [K in string | number | symbol]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }, Param>

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

    • Optional options: ParameterizedOperationOptions<Param>

      The operation options.

    Returns ObjectShape<PropShapes, RestShape>

    The clone of the shape.

  • Adds a synchronous operation to the shape.

    Parameters

    • cb: OperationCallback<Result<{
          [K in string | number | symbol]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }>, {
          [K in string | number | symbol]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }>

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

    • Optional options: OperationOptions

      The operation options.

    Returns ObjectShape<PropShapes, RestShape>

    The clone of the shape.

  • Allows an input value, so it is passed directly to the output.

    Type Parameters

    • AllowedValue extends Any

      The allowed value.

    Parameters

    • value: AllowedValue

      The allowed value.

    Returns AllowShape<ObjectShape<PropShapes, RestShape>, AllowedValue>

  • 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]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }, {
          [K in string | number | symbol]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }, 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 ObjectShape<PropShapes, RestShape>

    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]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }, {
          [K in string | number | symbol]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }>

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

    • Optional options: OperationOptions

      The operation options.

    Returns ObjectShape<PropShapes, RestShape>

    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]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }>, {
          [K in string | number | symbol]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }, 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 ObjectShape<PropShapes, RestShape>

    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]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }>, {
          [K in string | number | symbol]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }>

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

    • Optional options: OperationOptions

      The operation options.

    Returns ObjectShape<PropShapes, RestShape>

    The clone of the shape.

  • Adds annotations to the shape.

    Parameters

    • annotations: ReadonlyDict<any>

      Annotations to add.

    Returns ObjectShape<PropShapes, RestShape>

    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: any

      The key for which the sub-shape must be retrieved.

    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<ObjectShape<PropShapes, RestShape>, Branded<{
        [K in string | number | symbol]: (Omit<{
            [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
        }, OptionalKeys<{
            [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
        }>> & {
            [K in string | number | symbol]?: {
                [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
            }[K]
        } & (RestShape extends undefined | null
            ? {}
            : RestShape extends Shape<any, any>
                ? {
                    [key: string]: RestShape[Leg];
                }
                : {}))[K]
    }, Brand>>

    A shape with the branded output type.

  • Returns undefined if parsing fails.

    Returns CatchShape<ObjectShape<PropShapes, RestShape>, undefined>

  • Returns the fallback value if parsing fails.

    Type Parameters

    • FallbackValue extends Any

      The fallback value.

    Parameters

    • fallback: FallbackValue | ((input, issues, options) => FallbackValue)

      The value or a callback that returns a value that is returned if parsing has failed. A callback receives an input value, an array of raised issues, and parsing options.

    Returns CatchShape<ObjectShape<PropShapes, RestShape>, FallbackValue>

  • 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]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }, 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 ObjectShape<PropShapes, RestShape>

    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]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }>

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

    • Optional options: OperationOptions

      The operation options.

    Returns ObjectShape<PropShapes, RestShape>

    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]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }, 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 ObjectShape<PropShapes, RestShape>

    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]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }>

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

    • Optional options: OperationOptions

      The operation options.

    Returns ObjectShape<PropShapes, RestShape>

    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, options) => ConvertedValue)

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

        • (value, options): ConvertedValue
        • Parameters

          • value: {
                [K in string | number | symbol]: (Omit<{
                    [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
                }, OptionalKeys<{
                    [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
                }>> & {
                    [K in string | number | symbol]?: {
                        [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
                    }[K]
                } & (RestShape extends undefined | null
                    ? {}
                    : RestShape extends Shape<any, any>
                        ? {
                            [key: string]: RestShape[Leg];
                        }
                        : {}))[K]
            }

            The shape output value.

          • options: ApplyOptions

            Parsing options.

          Returns ConvertedValue

    Returns Shape<{
        [K in string | number | symbol]: (Omit<{
            [K in string | number | symbol]: PropShapes[K][typeof INPUT]
        }, OptionalKeys<{
            [K in string | number | symbol]: PropShapes[K][typeof INPUT]
        }>> & {
            [K in string | number | symbol]?: {
                [K in string | number | symbol]: PropShapes[K][typeof INPUT]
            }[K]
        } & (RestShape extends undefined | null
            ? {}
            : RestShape extends Shape<any, any>
                ? {
                    [key: string]: RestShape[Leg];
                }
                : {}))[K]
    }, 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, options) => 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.

        • (value, options): PromiseLike<ConvertedValue>
        • Parameters

          • value: {
                [K in string | number | symbol]: (Omit<{
                    [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
                }, OptionalKeys<{
                    [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
                }>> & {
                    [K in string | number | symbol]?: {
                        [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
                    }[K]
                } & (RestShape extends undefined | null
                    ? {}
                    : RestShape extends Shape<any, any>
                        ? {
                            [key: string]: RestShape[Leg];
                        }
                        : {}))[K]
            }

            The shape output value.

          • options: ApplyOptions

            Parsing options.

          Returns PromiseLike<ConvertedValue>

    Returns Shape<{
        [K in string | number | symbol]: (Omit<{
            [K in string | number | symbol]: PropShapes[K][typeof INPUT]
        }, OptionalKeys<{
            [K in string | number | symbol]: PropShapes[K][typeof INPUT]
        }>> & {
            [K in string | number | symbol]?: {
                [K in string | number | symbol]: PropShapes[K][typeof INPUT]
            }[K]
        } & (RestShape extends undefined | null
            ? {}
            : RestShape extends Shape<any, any>
                ? {
                    [key: string]: RestShape[Leg];
                }
                : {}))[K]
    }, ConvertedValue>

    The ConvertShape instance.

  • Converts the shape and its child shapes to deep partial alternatives.

    Note: This method returns a shape without any operations.

    Returns DeepPartialObjectShape<PropShapes, RestShape>

    The deep partial clone of the shape.

  • Excludes value from both input and output.

    Type Parameters

    • DeniedValue extends {
          [K in string | number | symbol]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof INPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof INPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof INPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      } | {
          [K in string | number | symbol]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }

      The denied value.

    Parameters

    • value: DeniedValue

      The excluded value.

    • Optional options: IssueOptions | Message

      The issue options or the issue message.

    Returns DenyShape<ObjectShape<PropShapes, RestShape>, DeniedValue>

  • Returns an object shape that allows only known keys and has no index signature.

    Parameters

    Returns ObjectShape<PropShapes, null>

    The new object shape.

  • Checks that the input doesn't match the shape.

    Type Parameters

    • ExcludedShape extends AnyShape

      The shape to which the output must not conform.

    Parameters

    • shape: ExcludedShape

      The shape to which the output must not conform.

    • Optional options: IssueOptions | Message

      The issue options or the issue message.

    Returns ExcludeShape<ObjectShape<PropShapes, RestShape>, ExcludedShape>

  • Merge properties from the other object shape.

    Note: This method returns a shape without any operations.

    If a property with the same key already exists on this object shape then it is overwritten. The index signature of this shape and its ObjectShape.keysMode is preserved intact.

    Type Parameters

    • T extends ReadonlyDict<AnyShape>

      Properties to add.

    Parameters

    • shape: ObjectShape<T, any>

      The object shape which properties must be added to this object shape.

    Returns ObjectShape<Omit<PropShapes, keyof T> & T, RestShape>

    The new object shape.

  • Add properties to an object shape.

    Note: This method returns a shape without any operations.

    If a property with the same key already exists on this object shape then it is overwritten. The index signature of this shape and its ObjectShape.keysMode is preserved intact.

    Type Parameters

    • T extends ReadonlyDict<AnyShape>

      The shapes of properties to add.

    Parameters

    • shapes: T

      The properties to add.

    Returns ObjectShape<Omit<PropShapes, keyof T> & T, RestShape>

    The new object shape.

  • Checks that the input doesn't match the shape.

    This method works exactly as Shape.exclude at runtime, but it doesn't perform the exclusion on the type level.

    Type Parameters

    • ExcludedShape extends AnyShape

      The shape to which the output must not conform.

    Parameters

    • shape: ExcludedShape

      The shape to which the output must not conform.

    • Optional options: IssueOptions | Message

      The issue options or the issue message.

    Returns NotShape<ObjectShape<PropShapes, RestShape>, ExcludedShape>

  • Replaces null input value with an null output value.

    Returns AllowShape<ObjectShape<PropShapes, RestShape>, null>

  • Replaces null input value with a default output value.

    Type Parameters

    • DefaultValue extends Any

      The value that is used as the replacement for null.

    Parameters

    • defaultValue: DefaultValue

      The value that should be used if an input value is null.

    Returns ReplaceShape<ObjectShape<PropShapes, RestShape>, null, DefaultValue>

  • Passes null and undefined input values directly to the output without parsing.

    Returns AllowShape<AllowShape<ObjectShape<PropShapes, RestShape>, null>, undefined>

  • Replaces null and undefined input value with a default output value.

    Type Parameters

    • DefaultValue extends Any

      The value that is used as the replacement for undefined and null.

    Parameters

    • Optional defaultValue: DefaultValue

      The value that should be used if an input value is undefined or null.

    Returns ReplaceShape<ReplaceShape<ObjectShape<PropShapes, RestShape>, null, DefaultValue>, undefined, DefaultValue>

  • Returns an object shape that doesn't have the listed keys.

    Note: This method returns a shape without any operations.

    Type Parameters

    • K extends readonly (keyof PropShapes)[]

      The tuple of keys to omit.

    Parameters

    • keys: K

      The array of property keys to omit.

    Returns ObjectShape<Omit<PropShapes, K[number]>, RestShape>

    The new object shape.

  • Replaces undefined input value with an undefined output value.

    Returns AllowShape<ObjectShape<PropShapes, RestShape>, undefined>

  • Replaces undefined input value with a default output value.

    Type Parameters

    • DefaultValue extends Any

      The value that is used as the replacement for undefined.

    Parameters

    • defaultValue: DefaultValue

      The value that should be used if an input value is undefined.

    Returns ReplaceShape<ObjectShape<PropShapes, RestShape>, undefined, DefaultValue>

  • Synchronously parses the value.

    Parameters

    • input: unknown

      The value to parse.

    • Optional options: ParseOptions

      Parsing options.

    Returns {
        [K in string | number | symbol]: (Omit<{
            [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
        }, OptionalKeys<{
            [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
        }>> & {
            [K in string | number | symbol]?: {
                [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
            }[K]
        } & (RestShape extends undefined | null
            ? {}
            : RestShape extends Shape<any, any>
                ? {
                    [key: string]: RestShape[Leg];
                }
                : {}))[K]
    }

    The value that conforms the output type of the shape.

    Throws

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

    Throws

    ValidationError if any issues occur during parsing.

  • Asynchronously parses the value.

    Parameters

    • input: unknown

      The value to parse.

    • Optional options: ParseOptions

      Parsing options.

    Returns Promisify<{
        [K in string | number | symbol]: (Omit<{
            [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
        }, OptionalKeys<{
            [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
        }>> & {
            [K in string | number | symbol]?: {
                [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
            }[K]
        } & (RestShape extends undefined | null
            ? {}
            : RestShape extends Shape<any, any>
                ? {
                    [key: string]: RestShape[Leg];
                }
                : {}))[K]
    }>

    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]: (Omit<{
            [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
        }, OptionalKeys<{
            [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
        }>> & {
            [K in string | number | symbol]?: {
                [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
            }[K]
        } & (RestShape extends undefined | null
            ? {}
            : RestShape extends Shape<any, any>
                ? {
                    [key: string]: RestShape[Leg];
                }
                : {}))[K]
    }

    The value that conforms the output type of the shape.

    Throws

    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.

    • Optional options: ApplyOptions

      Parsing options.

    Returns {
        [K in string | number | symbol]: (Omit<{
            [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
        }, OptionalKeys<{
            [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
        }>> & {
            [K in string | number | symbol]?: {
                [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
            }[K]
        } & (RestShape extends undefined | null
            ? {}
            : RestShape extends Shape<any, any>
                ? {
                    [key: string]: RestShape[Leg];
                }
                : {}))[K]
    } | DefaultValue

    The value that conforms the output type of the shape.

    Throws

    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]: (Omit<{
            [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
        }, OptionalKeys<{
            [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
        }>> & {
            [K in string | number | symbol]?: {
                [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
            }[K]
        } & (RestShape extends undefined | null
            ? {}
            : RestShape extends Shape<any, any>
                ? {
                    [key: string]: RestShape[Leg];
                }
                : {}))[K]
    }>

    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.

    • Optional options: ApplyOptions

      Parsing options.

    Returns Promisify<{
        [K in string | number | symbol]: (Omit<{
            [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
        }, OptionalKeys<{
            [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
        }>> & {
            [K in string | number | symbol]?: {
                [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
            }[K]
        } & (RestShape extends undefined | null
            ? {}
            : RestShape extends Shape<any, any>
                ? {
                    [key: string]: RestShape[Leg];
                }
                : {}))[K]
    } | DefaultValue>

    The value that conforms the output type of the shape.

  • Returns an object shape with all properties marked as optional.

    Note: This method returns a shape without any operations.

    Returns ObjectShape<OptionalPropShapes<PropShapes>, RestShape>

    The new object shape.

  • Returns an object shape with keys marked as optional.

    Note: This method returns a shape without any operations.

    Type Parameters

    • K extends readonly (keyof PropShapes)[]

      The array of string keys.

    Parameters

    • keys: K

      The array of property keys to make optional.

    Returns ObjectShape<Omit<PropShapes, K[number]> & OptionalPropShapes<Pick<PropShapes, K[number]>>, RestShape>

    The new object shape.

  • Returns an object shape that only has properties with listed keys.

    Note: This method returns a shape without any operations.

    Type Parameters

    • K extends readonly (keyof PropShapes)[]

      The tuple of keys to pick.

    Parameters

    • keys: K

      The array of property keys to pick.

    Returns ObjectShape<Pick<PropShapes, K[number]>, RestShape>

    The new object shape.

  • Returns an object shape that has an index signature that doesn't constrain values.

    Returns ObjectShape<PropShapes, null>

    The new object shape.

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

    Type Parameters

    • RefinedValue extends {
          [K in string | number | symbol]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }

      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]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }, 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<ObjectShape<PropShapes, 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]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }

      The narrowed output value.

    Parameters

    • cb: RefinePredicate<{
          [K in string | number | symbol]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }, RefinedValue>

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

    • Optional options: Message | RefineOptions

      The operation options or the issue message.

    Returns RefineShape<ObjectShape<PropShapes, 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]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }, Param>

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

    • Optional options: Message | ParameterizedRefineOptions<Param>

      The operation options or the issue message.

    Returns ObjectShape<PropShapes, RestShape>

    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]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }>

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

    • Optional options: Message | RefineOptions

      The operation options or the issue message.

    Returns ObjectShape<PropShapes, RestShape>

    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]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }, Param>

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

    • Optional options: Message | ParameterizedRefineOptions<Param>

      The operation options or the issue message.

    Returns ObjectShape<PropShapes, RestShape>

    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]: (Omit<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }, OptionalKeys<{
              [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
          }>> & {
              [K in string | number | symbol]?: {
                  [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
              }[K]
          } & (RestShape extends undefined | null
              ? {}
              : RestShape extends Shape<any, any>
                  ? {
                      [key: string]: RestShape[Leg];
                  }
                  : {}))[K]
      }>

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

    • Optional options: Message | RefineOptions

      The operation options or the issue message.

    Returns ObjectShape<PropShapes, RestShape>

    The clone of the shape.

  • Replaces an input value with an output value.

    Type Parameters

    • InputValue extends Any

      The input value to replace.

    • OutputValue extends Any

      The output value that is used as the replacement for an input value.

    Parameters

    • inputValue: InputValue

      The input value to replace.

    • outputValue: OutputValue

      The output value that is returned if an inputValue is received.

    Returns ReplaceShape<ObjectShape<PropShapes, RestShape>, InputValue, OutputValue>

  • Returns an object shape with all properties marked as required.

    Returns ObjectShape<RequiredPropShapes<PropShapes>, RestShape>

    The new object shape.

  • Returns an object shape with keys marked as required.

    Type Parameters

    • K extends readonly (keyof PropShapes)[]

      The array of string keys.

    Parameters

    • keys: K

      The array of property keys to make required.

    Returns ObjectShape<Omit<PropShapes, K[number]> & RequiredPropShapes<Pick<PropShapes, K[number]>>, RestShape>

    The new object shape.

  • Returns an object shape that has an index signature that is constrained by the given shape.

    Type Parameters

    • S extends null | AnyShape

      The index signature shape.

    Parameters

    Returns ObjectShape<PropShapes, S>

    The new object shape.

  • Returns an object shape that doesn't have an index signature and all unknown keys are stripped.

    Returns ObjectShape<PropShapes, null>

    The new object shape.

  • Pipes the output of this shape to the input of another shape.

    Type Parameters

    • OutputShape extends AnyShape

      The output value.

    Parameters

    • shape: OutputShape

      The shape that validates the output if this shape.

    Returns PipeShape<ObjectShape<PropShapes, RestShape>, OutputShape>

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

    Parameters

    • input: unknown

      The value to parse.

    • Optional options: ApplyOptions

      Parsing options.

    Returns Err | Ok<{
        [K in string | number | symbol]: (Omit<{
            [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
        }, OptionalKeys<{
            [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
        }>> & {
            [K in string | number | symbol]?: {
                [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
            }[K]
        } & (RestShape extends undefined | null
            ? {}
            : RestShape extends Shape<any, any>
                ? {
                    [key: string]: RestShape[Leg];
                }
                : {}))[K]
    }>

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

    Throws

    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.

    • Optional options: ApplyOptions

      Parsing options.

    Returns Promise<Err | Ok<{
        [K in string | number | symbol]: (Omit<{
            [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
        }, OptionalKeys<{
            [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
        }>> & {
            [K in string | number | symbol]?: {
                [K in string | number | symbol]: PropShapes[K][typeof OUTPUT]
            }[K]
        } & (RestShape extends undefined | null
            ? {}
            : RestShape extends Shape<any, any>
                ? {
                    [key: string]: RestShape[Leg];
                }
                : {}))[K]
    }>>

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

Plugin Methods

  • Defines an all-or-nothing relationship between keys where if one of the keys is present, all of them are required as well.

    Type Parameters

    • K extends readonly (keyof PropShapes)[]

    Parameters

    • keys: K

      The keys of which, if one present, all are required.

    • Optional options: IssueOptions | Message

      The issue options or the issue message.

    Returns ObjectShape<PropShapes, RestShape>

    The clone of the shape.

  • Defines a relationship between keys where not all peers can be present at the same time.

    Type Parameters

    • K extends readonly (keyof PropShapes)[]

    Parameters

    • keys: K

      The keys of which, if one present, the others may not all be present.

    • Optional options: IssueOptions | Message

      The issue options or the issue message.

    Returns ObjectShape<PropShapes, RestShape>

    The clone of the shape.

  • Defines a relationship between keys where at least one of the keys is required (and more than one is allowed).

    Type Parameters

    • K extends readonly (keyof PropShapes)[]

    Parameters

    • keys: K

      The keys of which at least one must appear.

    • Optional options: IssueOptions | Message

      The issue options or the issue message.

    Returns ObjectShape<PropShapes, RestShape>

    The clone of the shape.

  • Defines an exclusive relationship between a set of keys where only one is allowed but none are required.

    Type Parameters

    • K extends readonly (keyof PropShapes)[]

    Parameters

    • keys: K

      The exclusive keys that must not appear together but where none are required.

    • Optional options: IssueOptions | Message

      The issue options or the issue message.

    Returns ObjectShape<PropShapes, RestShape>

    The clone of the shape.

  • Defines an exclusive relationship between a set of keys where one of them is required but not at the same time.

    Type Parameters

    • K extends readonly (keyof PropShapes)[]

    Parameters

    • keys: K

      The exclusive keys that must not appear together but where one of them is required.

    • Optional options: IssueOptions | Message

      The issue options or the issue message.

    Returns ObjectShape<PropShapes, RestShape>

    The clone of the shape.

Accessors

  • get keysShape(): EnumShape<keyof PropShapes>
  • The enum shape that describes object keys.

    Returns EnumShape<keyof PropShapes>