Skip to content
1 min read · 165 words

Function: asyncValidateOrThrow() ​

ts
function asyncValidateOrThrow<T>(
  schema: Schema,
  value: unknown,
  convert?: boolean,
): Promise<T>;

Defined in: src/lib/utils/validation.ts:136

Validates value against schema asynchronously and returns the coerced result typed as T.

Type Parameters ​

Type ParameterDescription
TThe expected type of the validated and coerced return value.

Parameters ​

ParameterTypeDefault valueDescription
schemaSchemaundefinedThe schema to validate against.
valueunknownundefinedThe value to validate.
convertbooleanfalseWhen true, the validator coerces values to their target types (e.g. string "1" → number 1). Defaults to false to prevent silent type coercion.

Returns ​

Promise<T>

The validated (and optionally coerced) value typed as T.

Remarks ​

Collects all field errors before throwing. Prefer this over validateOrThrow when the schema includes async custom validators.

Throws ​

ValidationException when value does not satisfy schema.