Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Improve inference to union and intersection types#29847

Merged
ahejlsberg merged 7 commits into
mastermicrosoft/TypeScript:masterfrom
inferToUnionTypesmicrosoft/TypeScript:inferToUnionTypesCopy head branch name to clipboard
Feb 11, 2019
Merged

Improve inference to union and intersection types#29847
ahejlsberg merged 7 commits into
mastermicrosoft/TypeScript:masterfrom
inferToUnionTypesmicrosoft/TypeScript:inferToUnionTypesCopy head branch name to clipboard

Conversation

@ahejlsberg

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

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.