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/union or intersection/intersection type inference #5942

Merged
merged 3 commits into from
Dec 5, 2015

Conversation

ahejlsberg
Copy link
Member

The reduction step introduced in #5738 is a bit too aggressive. For example:

interface Foo<T> {
    x: T;
}

function bar<T>(x: Foo<T> | string): T {
    return bar(x);
}

In the bar(x) call we infer from Foo<T> | string to Foo<T> | string which previously was reduced to empty types (and thus no inferences) because all constituents are pairwise identical. Therefore, the above would be an error. With this PR we instead find all of the pairwise identical constituents and infer from each match to itself. We then remove the pairwise matches and proceed with the already existing inference algorithm.

@ahejlsberg ahejlsberg added this to the TypeScript 1.8 milestone Dec 5, 2015
@ahejlsberg ahejlsberg assigned ahejlsberg and unassigned ahejlsberg Dec 5, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Dec 5, 2015

👍

1 similar comment
@vladima
Copy link
Contributor

vladima commented Dec 5, 2015

👍

ahejlsberg added a commit that referenced this pull request Dec 5, 2015
Fix union/union or intersection/intersection type inference
@ahejlsberg ahejlsberg merged commit 3ce91c4 into master Dec 5, 2015
@ahejlsberg ahejlsberg deleted the fixUnionToUnionTypeInference branch December 5, 2015 17:28
@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