Closed
Description
π Search Terms
"excessive stack depth", "ts2321"
π Version & Regression Information
- This changed in commit or PR Improve constraints of conditional types applied to constrained type variablesΒ #56004
β― Playground Link
π» Code
type ReadonlyTuple<T, N extends number, R extends Array<T> = []> =
R['length'] extends N
? readonly [...R]
: ReadonlyTuple<T, N, [T, ...R]>;
type ArrayMinN<T, N extends number> = number extends N
? Array<T>
: N extends 0
? Array<T>
: [...ReadonlyTuple<T, N>, ...Array<T>];
declare function hasAtLeast<T, N extends number>(
data: ReadonlyArray<T>,
minimum: N,
): data is ArrayMinN<T, N>;
π Actual behavior
The function hasAtLeast
does not typecheck, with an error on the return type data is ArrayMinN<T, N>;
: "Excessive stack depth comparing types 'ArrayMinN<T, N>' and 'readonly T[]'.(2321)"
π Expected behavior
No type error.
Additional information about the issue
This was reported in remeda/remeda#572.
It's not clear to me whether this is working as intended, though it is a regression. It's not hard to rewrite the type to make it work, but wondering if it's a Deeper Problemβ’.