Skip to content

Fix 'infer T' type parameter leaks#22959

Merged
ahejlsberg merged 5 commits into
masterfrom
fixInferTypeParameterLeak
Mar 28, 2018
Merged

Fix 'infer T' type parameter leaks#22959
ahejlsberg merged 5 commits into
masterfrom
fixInferTypeParameterLeak

Conversation

@ahejlsberg
Copy link
Copy Markdown
Member

With this PR we properly erase 'infer T' type parameters to their constraints when producing the base constraint of a conditional type. For example:

function foo<T>(x: T extends (infer U)[] ? U[] : never) {
    let e = x[0];  // {}
}

Previously the U type parameter would leak and become the type of e.

@ahejlsberg ahejlsberg requested a review from mhegazy March 28, 2018 20:20
@ahejlsberg ahejlsberg added this to the TypeScript 2.8.2 milestone Mar 28, 2018
@DanielRosenwasser
Copy link
Copy Markdown
Member

DanielRosenwasser commented Mar 28, 2018

Can we have a test that infers from a type parameter with an explicit constraint?

function foo2<T extends string[]>(x: T extends (infer U)[] ? U[] : never) {
    let e = x[0];
}

@ahejlsberg ahejlsberg merged commit 9dd3148 into master Mar 28, 2018
@ahejlsberg ahejlsberg deleted the fixInferTypeParameterLeak branch March 28, 2018 22:45
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants