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

Suboptimal inference to unions like T | Promise<T> #32434

Closed
ahejlsberg opened this issue Jul 16, 2019 · 0 comments · Fixed by #32460
Closed

Suboptimal inference to unions like T | Promise<T> #32434

ahejlsberg opened this issue Jul 16, 2019 · 0 comments · Fixed by #32460
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@ahejlsberg
Copy link
Member

TypeScript Version: 3.6.0-dev

Code

declare function foo<T>(x: T | Promise<T>): void;
declare let x: false | Promise<true>;
foo(x);  // Error, 'false | Promise<true>' not assignable to 'true | Promise<true>'

declare function bar<T>(x: T, y: string | T): T;
const y = bar(1, 2);  // Error, '2' not assignable to 'string | 1'

Expected behavior: No errors.

Actual behavior: Errors as noted above.

Playground Link: https://www.typescriptlang.org/play/index.html#code/CYUwxgNghgTiAEAzArgOzAFwJYHtVJxwB4AVAPgAoAPALnhPgB94AFGHAWywGcRSyAlHQBuOLMADcAWABQoSLAQQQGeLSRQIvJq3ZdeRDDGQgy0mYkLUBE+PAD09+AFEY7GLNnzocJGky4+ABGsPzUdCQANPAAnnTcRlioAOY6JEL05mB4CbHwALzwITAUAIzRAEw2do4ubjgeMkA

Related Issues: Discovered in #32386.

@ahejlsberg ahejlsberg self-assigned this Jul 16, 2019
@ahejlsberg ahejlsberg added the Bug A bug in TypeScript label Jul 16, 2019
@ahejlsberg ahejlsberg added this to the TypeScript 3.6.1 milestone Jul 23, 2019
@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Jul 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant