Skip to content

Wrong type inference with tuples #22432

@falsandtru

Description

@falsandtru

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions