Vinyl
    Preparing search index...

    Interface PropertyValidator<T, PropertyOptionsType>

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

    interface PropertyValidator<
        T,
        PropertyOptionsType extends PropertyValidatorOptions,
    > {
        __type?: Invariant<T>;
        assert: (
            input: unknown,
            origin?: string,
            path?: readonly string[],
        ) => asserts input is T;
        description: string;
        isValid: (input: unknown) => input is T;
        options: PropertyOptionsType;
        validate: (
            input: unknown,
            options?: ValidationOptions,
            path?: readonly string[],
        ) => readonly ValidationErrorMessage[];
        optional(): PropertyValidatorWithOptions<
            PropertyValidator<T, PropertyOptionsType>,
            T,
            { optional: true },
        >;
        required(): PropertyValidatorWithOptions<
            PropertyValidator<T, PropertyOptionsType>,
            T,
            { optional: false },
        >;
    }

    Type Parameters

    Hierarchy (View Summary)

    Implemented by

    Index

    Properties

    __type?: Invariant<T>

    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.

    assert: (
        input: unknown,
        origin?: string,
        path?: readonly string[],
    ) => asserts input is T

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

    Type declaration

      • (input: unknown, origin?: string, path?: readonly string[]): asserts input is T
      • Parameters

        • input: unknown

          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 T

        Returns the input, cast as the validated type T

    description: string

    A short description of the validator.

    isValid: (input: unknown) => input is T

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

    validate: (
        input: unknown,
        options?: ValidationOptions,
        path?: readonly string[],
    ) => readonly ValidationErrorMessage[]

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

    Type declaration

      • (
            input: unknown,
            options?: ValidationOptions,
            path?: readonly string[],
        ): readonly ValidationErrorMessage[]
      • Parameters

        • input: unknown

          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.

    Methods