Skip to content

Allow array concat to concat arrays of different types #31355

@chiawendt

Description

@chiawendt

TypeScript Version: 3.5.0-dev.20190511

Code

[0].concat('')
// Argument of type '""' is not assignable to parameter of type 'number | ConcatArray<number>'.

Expected behavior:
The concated array has type (number|string)[].

Actual behavior:
Error.

Possible fix:
In

concat(...items: ConcatArray<T>[]): T[];

interface Array<T> {
- concat(...items: ConcatArray<T>[]): T[];
+ concat<U>(...items: ConcatArray<U>[]): (T|U)[];

Playground Link:
https://www.typescriptlang.org/play/#src=%5B0%5D.concat(%5B''%5D)

Related Issues:
#29604

Search Terms:
array concat

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions