镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
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

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:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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 consensus

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions