Skip to content

validate

@tsed/ajv

Usage

typescript
import { validate } from "@tsed/ajv";

See /packages/specs/ajv/src/fn/validate.ts.

Overview

ts
function validate<TReturn = never, TValue = unknown>(value: TValue, options: AjvValidateOptions | JsonSchema): Promise<[TReturn] extends [never] ? TValue : TReturn>;
  • value (TValue): Value to validate.

  • options (AjvValidateOptions | JsonSchema): Validation options, a JSON schema, or a target type descriptor.

Description

Validate a value against a JSON schema or a type using the configured AjvService.

The return type is inferred from value by default and can be overridden with an explicit generic: validate<MyType>(value, options).

Released under the MIT License.