type-alias / @typed/router/Parser

Parser.TakeWhileInternal

Recursively consumes an allowed character prefix at the type level.

Package version
1.0.0-beta.13
Category
Parser repetition
Since
1.0.0
Member of
Parser

Import

import { Parser } from "@typed/router/Parser";

Access Parser.TakeWhileInternal through the imported Parser export. Its declaration below describes the member.

Signatures

type TakeWhileInternal<Input extends string, Allowed extends string, Acc extends string = ""> = Input extends `${infer Head}${infer Tail}` ? Head extends Allowed ? TakeWhileInternal<Tail, Allowed, `${Acc}${Head}`> : readonly [
    Acc,
    Input
] : readonly [
    Acc,
    Input
];

Why

The public TakeWhile combinator preserves both the accumulated prefix and exact remainder.

Ownership and lifetime

TypeScript recursively instantiates TakeWhileInternal while characters remain allowed. Its accumulator and remainder are erased after type checking.

Source