Skip to content

Improve inference to union and intersection types - #29847

Merged
Anders Hejlsberg (ahejlsberg) merged 7 commits into
masterfrom
inferToUnionTypes
Feb 11, 2019
Merged

Improve inference to union and intersection types#29847
Anders Hejlsberg (ahejlsberg) merged 7 commits into
masterfrom
inferToUnionTypes

Conversation

@ahejlsberg

@ahejlsberg Anders Hejlsberg (ahejlsberg) commented Feb 10, 2019

Copy link
Copy Markdown
Member

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 Anders Hejlsberg (ahejlsberg) changed the title Improve inference to union types Improve inference to union and intersection types Feb 10, 2019
@weswigham

Copy link
Copy Markdown
Member

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

@ahejlsberg

Copy link
Copy Markdown
Member Author

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

@ahejlsberg
Anders Hejlsberg (ahejlsberg) deleted the inferToUnionTypes branch February 11, 2019 19:34
@weswigham

Copy link
Copy Markdown
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.

2 participants