Skip to content

Type inference doesn't work with union types of tuples #22564

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

Closed
falsandtru opened this issue Mar 14, 2018 · 1 comment
Closed

Type inference doesn't work with union types of tuples #22564

falsandtru opened this issue Mar 14, 2018 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@falsandtru
Copy link
Contributor

separated from #22432

TypeScript Version: 2.7.0-dev.20180307

Search Terms:

Code

type A<R> = [R] | [R, string];
declare function f<T>(f: A<T>): void;
f([undefined, ''] as [never, string]); // T: string
f([undefined, ''] as [void, string]); // T: string | void

Expected behavior:

f([undefined, ''] as [never, string]); // T: never
f([undefined, ''] as [void, string]); // T: void

Actual behavior:

f([undefined, ''] as [never, string]); // T: string
f([undefined, ''] as [void, string]); // T: string | void

Playground Link:

Related Issues:

@ghost
Copy link

ghost commented Mar 14, 2018

Worth noting that the following compiles:

f<number>([undefined, ''] as [never, string]);

because never is assignable to number.

@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label Mar 14, 2018
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 2.9 milestone Mar 14, 2018
@ahejlsberg ahejlsberg self-assigned this Mar 23, 2018
@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Mar 24, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants