Skip to content

Type alias recursion is resolved eagerly when the alias is generic and its arguments are derived from inferred members of conditional types #37801

Closed
@dead-claudia

Description

@dead-claudia

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:

Metadata

Metadata

Assignees

Labels

Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureFix AvailableA PR has been opened for this issueIn DiscussionNot yet reached consensusfeature-requestA request for a new feature

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions