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

Improve inference to union and intersection types #29847

Merged
merged 7 commits into from
Feb 11, 2019
Merged

Conversation

ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Feb 10, 2019

This PR improves inference to union and intersection types containing multiple naked type variables. Previously we would make no inferences to such union and intersection types (for unrelated historical reasons that no longer apply). We now make the the proper inferences:

declare function f1<T, U>(x: T | U): T | U;
declare function f2<T, U>(x: T & U): T & U;

let x1: string = f1('a');
let x2: string = f2('a');

Previously both assignments were errors because we'd infer {} for T and U.

Fixes #29815.

@ahejlsberg ahejlsberg changed the title Improve inference to union types Improve inference to union and intersection types Feb 10, 2019
@weswigham
Copy link
Member

Since I'm curious, what prompted us to only infer to one naked type parameter originally, anyway?

@ahejlsberg
Copy link
Member Author

@weswigham I think it was a holdover from when we didn't have priorities associated with inference candidates.

@ahejlsberg ahejlsberg merged commit f93f4f3 into master Feb 11, 2019
@ahejlsberg ahejlsberg deleted the inferToUnionTypes branch February 11, 2019 19:34
@weswigham
Copy link
Member

Huh. I wonder why we didn't remove it when we added the NakedTypeParameter priority, then.
🤷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants