Skip to content

Wrong type inference with tuples #22432

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 9, 2018 · 4 comments
Closed

Wrong type inference with tuples #22432

falsandtru opened this issue Mar 9, 2018 · 4 comments

Comments

@falsandtru
Copy link
Contributor

falsandtru commented Mar 9, 2018

TypeScript Version: 2.7.0-dev.20180307

Search Terms:

Code

Expected behavior:

type B<R, S> = [R] | [R, S];
declare function g<T, U>(f: B<T, U>): void;
g([[]] as [never[]]); // T: never[], U: {}
g([[]] as [void[]]); // T: void[], U: {}

type C<R, S> = [R[]] | [R[], S];
declare function h<T, U>(f: C<T, U>): void;
h([[]] as [never[]]); // T: never, U: {}
h([[]] as [void[]]); // T: void, U: {}

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

Actual behavior:

type B<R, S> = [R] | [R, S];
declare function g<T, U>(f: B<T, U>): void;
g([[]] as [never[]]); // T: never[], U: {}
g([[]] as [void[]]); // T: void[], U: {}

type C<R, S> = [R[]] | [R[], S];
declare function h<T, U>(f: C<T, U>): void;
h([[]] as [never[]]); // T: never[], U: never[] | ConcatArray<never[]>
h([[]] as [void[]]); // T: void, U: void[] | ConcatArray<void[]>

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

Playground Link:

Related Issues:

@falsandtru falsandtru changed the title Type inference failures with tuples Wrong type inference with tuples Mar 9, 2018
@falsandtru
Copy link
Contributor Author

falsandtru commented Mar 9, 2018

h([[]] as [never[]]); // T: never[], U: never[] | ConcatArray<never[]>
f([[], ''] as [never[], string]); // T: string | never[], U: never[] | ConcatArray<string | never[]>

T should be never. U should be {}.

@falsandtru
Copy link
Contributor Author

@RyanCavanaugh
Copy link
Member

@falsandtru we'll get to this eventually but responses are typically much faster if there's some explanation of what's going on, or a short repro that gets precisely to the point

@falsandtru
Copy link
Contributor Author

Okay, I separated this into some issues.

@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
None yet
Projects
None yet
Development

No branches or pull requests

2 participants