Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,18 @@ type DecrementTuple<T extends unknown[], R extends number[] = []> = T extends [
// The actual decrement tuple, derived from the depth
type Decrement = DecrementTuple<BuildTuple<GrammarTokensDepth>>;

/**
* When the recursion limit is reached, the type system will use DeepRecursion instead of recursing further.
* It prevents the type from becoming “any” or “unknown” without explanation.
*/
type DeepRecursion = { __deepRecursion: true };

/**
* GrammarTokensRec is a recursive type that builds a partial record of token names as keys, with values that can be a RegExp, GrammarToken, or an array of those types.
* It uses the decrement tuple to count down the depth of recursion, preventing infinite loops.
*/
type GrammarTokensRec<Depth extends number = GrammarTokensDepth> = Depth extends 0
? never
? DeepRecursion
: Partial<
Record<
TokenName,
Expand Down