-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureFix AvailableA PR has been opened for this issueA PR has been opened for this issueIn DiscussionNot yet reached consensusNot yet reached consensusfeature-requestA request for a new featureA request for a new feature
Milestone
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.
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureFix AvailableA PR has been opened for this issueA PR has been opened for this issueIn DiscussionNot yet reached consensusNot yet reached consensusfeature-requestA request for a new featureA request for a new feature