Skip to content

createStandardSchemaV1

function createStandardSchemaV1<M, Opts>(parsers, options?): StandardSchemaV1<SchemaInput<M, Opts["partialOutput"] extends true ? true : false>, inferParserMapType<M>>;

Defined in: tanstack/core/standard-schema.ts:118

Build a Standard Schema from a parser map for use in a route’s validateSearch. The same parser definitions a component uses with useQueryStates can validate/type the route — without the component importing the route object.

Validation never fails for a search object: values are stringified and run through each parser, and absent or invalid keys resolve to the parser default (or null). Only a non-object input yields an issue. partialOutput: true makes the input type partial, so <Link search> can pass a subset of keys.

Type Parameter Default type
M extends ParserMap -
Opts extends CreateStandardSchemaOptions<M> CreateStandardSchemaOptions<M>
Parameter Type
parsers M
options? Opts

StandardSchemaV1<SchemaInput<M, Opts["partialOutput"] extends true ? true : false>, inferParserMapType<M>>

import { createFileRoute } from "@tanstack/react-router";
import { createStandardSchemaV1, parseAsIndex, parseAsString } from "@xtandard/lib/tanstack/server";
const tableSearch = {
pageIndex: parseAsIndex.withDefault(0),
sort: parseAsString.withDefault("createdAt"),
};
const schema = createStandardSchemaV1(tableSearch, { partialOutput: true });
schema["~standard"].validate({ pageIndex: "3" });
// → { value: { pageIndex: 2, sort: "createdAt" } }
export const Route = createFileRoute("/users")({ validateSearch: schema });