parseAsStringLiteral
function parseAsStringLiteral<T>(values): Parser<T>;Defined in: tanstack/core/built-in-parsers.ts:222
One of a fixed list of strings, typed as their union. Anything else parses to null.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T extends string |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
values |
readonly T[] |
Returns
Section titled “Returns”Parser<T>
Example
Section titled “Example”import { parseAsStringLiteral } from "@xtandard/lib/tanstack";
const sortOrder = parseAsStringLiteral(["asc", "desc"] as const); // Parser<"asc" | "desc">sortOrder.parse("asc"); // → "asc"sortOrder.parse("up"); // → null
const order = sortOrder.withDefault("asc");