Skip to content

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 Parameter
T extends number
Parameter Type
values readonly T[]

Parser<T>

import { parseAsNumberLiteral } from "@xtandard/lib/tanstack";
const pageSize = parseAsNumberLiteral([10, 25, 50] as const); // Parser<10 | 25 | 50>
pageSize.parse("25"); // → 25
pageSize.parse("30"); // → null
pageSize.serialize(50); // → "50"