parseAsNumberLiteral
function parseAsNumberLiteral<T>(values): Parser<T>;Defined in: tanstack/core/built-in-parsers.ts:246
One of a fixed list of numbers, typed as their union. Anything else parses
to null. Read with Number.parseFloat, like nuqs, so trailing junk is
ignored ("25px" → 25 when 25 is in the list).
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T extends number |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
values |
readonly T[] |
Returns
Section titled “Returns”Parser<T>
Example
Section titled “Example”import { parseAsNumberLiteral } from "@xtandard/lib/tanstack";
const pageSize = parseAsNumberLiteral([10, 25, 50] as const); // Parser<10 | 25 | 50>pageSize.parse("25"); // → 25pageSize.parse("30"); // → nullpageSize.serialize(50); // → "50"