Skip to content

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 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