validateWithStandardSchema
function validateWithStandardSchema<T>(schema, value): T;Defined in: tanstack/core/standard-schema.ts:58
Run a Standard Schema synchronously, returning its output or throwing.
Async validators are unsupported (matches nuqs parseAsJson).
Failed validation throws an Error whose message joins the issue messages
with "; "; an async schema throws a TypeError. parseAsJson and
parseAsStandardSchema use it and turn the throw into null. Handy in
custom parsers (wrap it in try/catch and return null).
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
schema |
StandardSchemaV1<unknown, T> |
value |
unknown |
Returns
Section titled “Returns”T
Example
Section titled “Example”import { validateWithStandardSchema } from "@xtandard/lib/tanstack";import * as v from "valibot";
const Email = v.pipe(v.string(), v.email("Invalid email"));validateWithStandardSchema(Email, "nope"); // throws Error: Invalid email