Skip to content

in conditional type, type parameter T is inferred as X, but [X] extends [T] is false #43123

Closed
@jcalz

Description

@jcalz

Bug Report

🔎 Search Terms

conditional inference, tuple, never

🕗 Version & Regression Information

⏯ Playground Link

Playground link

💻 Code

type Hmm = [0] extends [infer T, any?] ?
    [T, [0] extends [T] ? true : false]
    : never

🙁 Actual behavior

Hmm is evaluated as [0, false]. Somehow T is inferred as 0, but [0] doesn't extend [T]?

🙂 Expected behavior

Hmm should be evaluated as [0, true] as it does in TS 4.1.5 and below.

This behavior was brought up in a Stack Overflow question asking why it happens; not sure if there's any actual use case for this.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Conditional TypesThe issue relates to conditional typesFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions