diff --git a/src/types.d.ts b/src/types.d.ts index c772f369d5..e9cd275ff4 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -146,12 +146,18 @@ type DecrementTuple = T extends [ // The actual decrement tuple, derived from the depth type Decrement = DecrementTuple>; +/** + * 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 0 - ? never + ? DeepRecursion : Partial< Record< TokenName,