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: