Function: validateOrThrow()
ts
function validateOrThrow<T>(
schema: Schema,
value: unknown,
convert?: boolean,
): T;Defined in: src/lib/utils/validation.ts:113
Validates value against schema synchronously and returns the coerced result typed as T.
Type Parameters
| Type Parameter | Description |
|---|---|
T | The expected type of value after successful validation. |
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
schema | Schema | undefined | The schema to validate against. |
value | unknown | undefined | The value to validate. |
convert | boolean | false | When true, the validator coerces values to their target types (e.g. string "1" → number 1). Defaults to false to prevent silent type coercion. |
Returns
T
The validated (and optionally coerced) value typed as T.
Remarks
Collects all field errors before throwing. Use asyncValidateOrThrow for schemas that include async custom validators.
Throws
ValidationException when value does not satisfy schema.