Closed
Description
TypeScript Version: 3.9.0-beta
Search Terms: recursive, recursive generic
Code
type Intersect<U extends any[], R = unknown> =
((...u: U) => any) extends ((h: infer H, ...t: infer T) => any)
? Intersect<T, R & H>
: R
const value: Intersect<[{a: number}, {b: number}]> = {
a: 1,
b: 2
}
Note: the usual workaround of an immediately-indexed intermediate object type still works.
Expected behavior: It to type check without warnings
Actual behavior:
- At line 1:
Type alias 'Intersect' circularly references itself. (2456)
- At line 3:
Type 'Intersect' is not generic. (2315)
- At line 6:
Type 'Intersect' is not generic. (2315)
Playground Link: Link
Related Issues:
- Circularities Only Blocked Sometimes #37426 (root cause might be this)
- Recursive type alias in union type breaks in 3.8.3 #37344
- Probably about 25%-30% of all other recursive type issues.
- My use case is basically solving Tuple iteration and merging #26058 in userland, and doing this with
SomeTuple[number]
won't work because I don't want to recurse.