Skip to main content

Validate

Callable

  • Validate<T>(validators: ValidationOptions<T> | ValidationOptions<T>[], transform?: (value: any) => any): (target: any, propertyKey: string) => void

  • A @Validate is a property decorator to validate a property. It is typically used in Schema to validate schema properties.

    Validation runs on assignment, and a failure throws a ValidationTransactionError. Declaring constraints here is what lets a module reject bad inputs before any infrastructure is touched.

    @example
    @Validate({ options: { maxLength: 65535, minLength: 1 } })
    containerPort = Schema<number>();
    @group

    Decorators

    @see

    Techniques for Validation for the full list of constraints.


    Type parameters

    • T

    Parameters

    • validators: ValidationOptions<T> | ValidationOptions<T>[]

      One constraint, or an array of them. Each constraint carries the options to apply, and an optional destruct to reduce the property into the list of values the constraints run against. Without destruct, the property value is validated as-is.

    • optionaltransform: (value: any) => any

      Runs before validation, and replaces the stored value with what it returns.

      Returns (target: any, propertyKey: string) => void

        • (target: any, propertyKey: string): void
        • Parameters

          • target: any
          • propertyKey: string

          Returns void