Class CompilingHeterogeneousUnionValidator<S>

Lazily compiled validator for heterogeneous unions of objects. To improve performance, list the more frequently used types earlier in the union, and list each object's unique key first in its properties.

Type Parameters

  • S extends TUnion<TObject[]>

Hierarchy

  • AbstractCompilingTypedUnionValidator<S>
    • CompilingHeterogeneousUnionValidator

Constructors

Properties

schema: Readonly<S>

JSON schema against which to validate values. When a schema provides an errorMessage string option, all errors occurring for that schema (but not for nested schemas) collapse into a single error having this message. The errorMessage option allows you to provide a custom error message for a schema. For example, an errorMessage on a schema for a property of an object replaces TypeBox's built-in error messages for errors that occur on that property.

Methods

  • Inherit Doc

    Parameters

    • value: Readonly<unknown>
    • Optional overallError: string

    Returns void

  • Inherit Doc

    Parameters

    • value: unknown
    • Optional overallError: string

    Returns void

  • Inherit Doc

    Parameters

    • value: Readonly<unknown>
    • Optional overallError: string

    Returns Static<S, []>

  • Parameters

    • value: Readonly<unknown>
    • Optional overallError: string

    Returns TObject<TProperties>

  • Type Parameters

    • VS extends TSchema

    Parameters

    • schema: Readonly<VS>
    • value: Readonly<unknown>

    Returns Static<VS, []>

  • Type Parameters

    • VS extends TSchema

    Parameters

    • schema: Readonly<VS>
    • value: unknown

    Returns void

  • Parameters

    • value: Readonly<unknown>

    Returns number | ValueError

  • Validates a value against the schema and returns the first error, returning null if there is no error. No validation is performed beyond the first error, allowing you to protect the server from wasting time and memory validating excessively long strings. It is equivalent to calling next() exactly once on the iterator returned by errors(), serving only as a convenience method. For performance reasons, it is best to call test() before calling this method. This method does not throw ValidationException and does not clean values of unrecognized properties.

    Parameters

    • value: Readonly<unknown>

      Value to validate against the schema.

    Returns null | ValueError

    The first validation error, if there is a validation error, otherwise null.

  • Tests whether a value conforms to the schema, returning an iterable whose iterator yields the validation errors, or returning null if there are no validation errors. This method is equivalent to calling test() and then errors() and exists only for convenience. The method does not throw ValidationException and does not clean values of unrecognized properties.

    Parameters

    • value: Readonly<unknown>

      Value to validate against the schema.

    Returns null | Iterable<ValueError>

    An iteratable yielding all validation errors, if any, otherwise null. Upon detecting one or more errors for a particular schema (possibly a nested schema), if the schema provides an errorMessage property, only a single error is reported for the schema, and the message property of this error is set to errorMessage's value. Also, the TypeBox error "Expected required property" is dropped when at least one other error is reported for the property. Consequently, only the Type.Any and Type.Unknown schemas can yield "Expected required property" errors.

  • Tests whether a value conforms to the schema, returning the first error, or returning null if there is no error. This method is equivalent to calling test() and then firstError() and exists only for convenience. The method does not throw ValidationException and does not clean values of unrecognized properties.

    Parameters

    • value: Readonly<unknown>

      Value to validate against the schema.

    Returns null | ValueError

    The first validation error, if there is a validation error, otherwise null.

  • Parameters

    • schema: Readonly<TSchema>
    • value: Readonly<unknown>
    • Optional overallError: string

    Returns void

  • Parameters

    • schema: Readonly<TSchema>
    • value: Readonly<unknown>
    • Optional overallError: string

    Returns void

  • Inherit Doc

    Parameters

    • value: Readonly<unknown>
    • Optional overallError: string

    Returns void

  • Inherit Doc

    Parameters

    • value: unknown
    • Optional overallError: string

    Returns void

  • Inherit Doc

    Parameters

    • value: Readonly<unknown>
    • Optional overallError: string

    Returns Static<S, []>

  • Parameters

    • value: Readonly<unknown>
    • Optional overallError: string

    Returns TObject<TProperties>

Generated using TypeDoc