Skip to content

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

Closed
@ahejlsberg

Description

@ahejlsberg

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.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions