Interface ValidatorWithPartial<Output, Input>

A Validator can assert that an input matches this validator's schema.

interface ValidatorWithPartial<Output, Input> {
    __type?: Invariant<Output>;
    description: string;
    assert(input: Input, origin?: string, path?: readonly string[]): asserts input is Output;
    deepPartial(): ValidatorWithPartial<DeepPartial<Output> & Input, Input>;
    isValid(input: Input): input is Output;
    partial(): ValidatorWithPartial<Partial<Output> & Input, Input>;
    validate(input: Input, options?: ValidationOptions, path?: readonly string[]): readonly ValidationErrorMessage[];
}

Type Parameters

  • Output extends Input
  • Input

Hierarchy (view full)

Implemented by

Properties

__type?: Invariant<Output>

Enforces T is in an invariant position. This prevents a validator with more strict rules is assigned to a less strict type, which can cause unexpected validation errors.

description: string

A short description of the validator.

Methods

  • Validates the given input, asserting that the input is type T. If the input is not valid, a ValidationError will be thrown.

    Parameters

    • input: Input

      The input to validate.

    • Optionalorigin: string

      The error origin. ErrorOrigin.API by default.

    • Optionalpath: readonly string[]

      The current field path to this validator.

    Returns asserts input is Output

    Returns the input, cast as the validated type T

  • Returns true if the input is valid according to this validator.

    Parameters

    Returns input is Output

  • Validates the provided input, returning a list of error messages, or an empty array if the input passes this validator.

    Parameters

    • input: Input

      The input to validate.

    • Optionaloptions: ValidationOptions

      Validation options.

    • Optionalpath: readonly string[]

      The current field path to this validator.

    Returns readonly ValidationErrorMessage[]

    Returns an array of validation failures. If options.all is not true, only the first error will be returned.