Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix union type parameter inference #5895

Merged
merged 4 commits into from
Dec 3, 2015
Merged

Conversation

ahejlsberg
Copy link
Member

Fixes #5861.

@ahejlsberg
Copy link
Member Author

A bit more context on the fix. We previously would consider two type parameters identical if they were different type parameters but had identical constraints (but, oddly, wouldn't consider them assignable to each other). This of course isn't right, but it sort of worked when we were comparing constraints in generic signatures which was really the only time it would come up. However, we now sometimes need to compare type parameters for identity during union and intersection type inference (because of #5738) and we want different type parameters to actually be considered different, so we have to remove this logic. The effect is that we won't check whether type parameter constraints are identical when comparing generic signatures, as explained here.

declare function lift<U>(value: U | Foo<U>): Foo<U>;

function unlift<U>(value: U | Foo<U>): U {
return lift(value).prop; // error TS2322: Type '{}' is not assignable to type 'U'.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you remove the error comment

@sandersn
Copy link
Member

sandersn commented Dec 2, 2015

Could you also add a test for the case that type parameter constraints are not identical, but we don't check? It would be good to have as documentation in case do we go back and decide to start checking.

@sandersn
Copy link
Member

sandersn commented Dec 2, 2015

👍

ahejlsberg added a commit that referenced this pull request Dec 3, 2015
@ahejlsberg ahejlsberg merged commit 3bb5dc6 into master Dec 3, 2015
@ahejlsberg ahejlsberg deleted the unionTypeParameterInference branch December 3, 2015 20:23
ahejlsberg added a commit that referenced this pull request Dec 3, 2015
Fix union type parameter inference
Conflicts:
	src/compiler/checker.ts
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 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.

4 participants