Skip to content

Commit d2ad4a3

Browse files
author
Andy Hanson
committed
Array arguments to concat should be ReadonlyArrays
1 parent 80a7ed9 commit d2ad4a3

10 files changed

+42
-34
lines changed

src/lib/es5.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -980,12 +980,12 @@ interface ReadonlyArray<T> {
980980
* Combines two or more arrays.
981981
* @param items Additional items to add to the end of array1.
982982
*/
983-
concat(...items: T[][]): T[];
983+
concat(...items: ReadonlyArray<T>[]): T[];
984984
/**
985985
* Combines two or more arrays.
986986
* @param items Additional items to add to the end of array1.
987987
*/
988-
concat(...items: (T | T[])[]): T[];
988+
concat(...items: (T | ReadonlyArray<T>)[]): T[];
989989
/**
990990
* Adds all the elements of an array separated by the specified separator string.
991991
* @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.
@@ -1099,12 +1099,12 @@ interface Array<T> {
10991099
* Combines two or more arrays.
11001100
* @param items Additional items to add to the end of array1.
11011101
*/
1102-
concat(...items: T[][]): T[];
1102+
concat(...items: ReadonlyArray<T>[]): T[];
11031103
/**
11041104
* Combines two or more arrays.
11051105
* @param items Additional items to add to the end of array1.
11061106
*/
1107-
concat(...items: (T | T[])[]): T[];
1107+
concat(...items: (T | ReadonlyArray<T>)[]): T[];
11081108
/**
11091109
* Adds all the elements of an array separated by the specified separator string.
11101110
* @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.

tests/baselines/reference/arrayConcat2.types

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ var a: string[] = [];
55

66
a.concat("hello", 'world');
77
>a.concat("hello", 'world') : string[]
8-
>a.concat : { (...items: string[][]): string[]; (...items: (string | string[])[]): string[]; }
8+
>a.concat : { (...items: ReadonlyArray<string>[]): string[]; (...items: (string | ReadonlyArray<string>)[]): string[]; }
99
>a : string[]
10-
>concat : { (...items: string[][]): string[]; (...items: (string | string[])[]): string[]; }
10+
>concat : { (...items: ReadonlyArray<string>[]): string[]; (...items: (string | ReadonlyArray<string>)[]): string[]; }
1111
>"hello" : "hello"
1212
>'world' : "world"
1313

1414
a.concat('Hello');
1515
>a.concat('Hello') : string[]
16-
>a.concat : { (...items: string[][]): string[]; (...items: (string | string[])[]): string[]; }
16+
>a.concat : { (...items: ReadonlyArray<string>[]): string[]; (...items: (string | ReadonlyArray<string>)[]): string[]; }
1717
>a : string[]
18-
>concat : { (...items: string[][]): string[]; (...items: (string | string[])[]): string[]; }
18+
>concat : { (...items: ReadonlyArray<string>[]): string[]; (...items: (string | ReadonlyArray<string>)[]): string[]; }
1919
>'Hello' : "Hello"
2020

2121
var b = new Array<string>();
@@ -25,8 +25,8 @@ var b = new Array<string>();
2525

2626
b.concat('hello');
2727
>b.concat('hello') : string[]
28-
>b.concat : { (...items: string[][]): string[]; (...items: (string | string[])[]): string[]; }
28+
>b.concat : { (...items: ReadonlyArray<string>[]): string[]; (...items: (string | ReadonlyArray<string>)[]): string[]; }
2929
>b : string[]
30-
>concat : { (...items: string[][]): string[]; (...items: (string | string[])[]): string[]; }
30+
>concat : { (...items: ReadonlyArray<string>[]): string[]; (...items: (string | ReadonlyArray<string>)[]): string[]; }
3131
>'hello' : "hello"
3232

tests/baselines/reference/arrayConcatMap.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ var x = [].concat([{ a: 1 }], [{ a: 2 }])
44
>[].concat([{ a: 1 }], [{ a: 2 }]) .map(b => b.a) : any[]
55
>[].concat([{ a: 1 }], [{ a: 2 }]) .map : <U>(callbackfn: (value: any, index: number, array: any[]) => U, thisArg?: any) => U[]
66
>[].concat([{ a: 1 }], [{ a: 2 }]) : any[]
7-
>[].concat : { (...items: any[][]): any[]; (...items: any[]): any[]; }
7+
>[].concat : { (...items: ReadonlyArray<any>[]): any[]; (...items: any[]): any[]; }
88
>[] : undefined[]
9-
>concat : { (...items: any[][]): any[]; (...items: any[]): any[]; }
9+
>concat : { (...items: ReadonlyArray<any>[]): any[]; (...items: any[]): any[]; }
1010
>[{ a: 1 }] : { a: number; }[]
1111
>{ a: 1 } : { a: number; }
1212
>a : number

tests/baselines/reference/arrayOfSubtypeIsAssignableToReadonlyArray.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(13,1): error TS2322: Type 'A[]' is not assignable to type 'ReadonlyArray<B>'.
22
Types of property 'concat' are incompatible.
3-
Type '{ (...items: A[][]): A[]; (...items: (A | A[])[]): A[]; }' is not assignable to type '{ (...items: B[][]): B[]; (...items: (B | B[])[]): B[]; }'.
3+
Type '{ (...items: ReadonlyArray<A>[]): A[]; (...items: (A | ReadonlyArray<A>)[]): A[]; }' is not assignable to type '{ (...items: ReadonlyArray<B>[]): B[]; (...items: (B | ReadonlyArray<B>)[]): B[]; }'.
44
Type 'A[]' is not assignable to type 'B[]'.
55
Type 'A' is not assignable to type 'B'.
66
Property 'b' is missing in type 'A'.
77
tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(18,1): error TS2322: Type 'C<A>' is not assignable to type 'ReadonlyArray<B>'.
88
Types of property 'concat' are incompatible.
9-
Type '{ (...items: A[][]): A[]; (...items: (A | A[])[]): A[]; }' is not assignable to type '{ (...items: B[][]): B[]; (...items: (B | B[])[]): B[]; }'.
9+
Type '{ (...items: ReadonlyArray<A>[]): A[]; (...items: (A | ReadonlyArray<A>)[]): A[]; }' is not assignable to type '{ (...items: ReadonlyArray<B>[]): B[]; (...items: (B | ReadonlyArray<B>)[]): B[]; }'.
1010
Type 'A[]' is not assignable to type 'B[]'.
1111

1212

@@ -27,7 +27,7 @@ tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(18,1): error T
2727
~~~
2828
!!! error TS2322: Type 'A[]' is not assignable to type 'ReadonlyArray<B>'.
2929
!!! error TS2322: Types of property 'concat' are incompatible.
30-
!!! error TS2322: Type '{ (...items: A[][]): A[]; (...items: (A | A[])[]): A[]; }' is not assignable to type '{ (...items: B[][]): B[]; (...items: (B | B[])[]): B[]; }'.
30+
!!! error TS2322: Type '{ (...items: ReadonlyArray<A>[]): A[]; (...items: (A | ReadonlyArray<A>)[]): A[]; }' is not assignable to type '{ (...items: ReadonlyArray<B>[]): B[]; (...items: (B | ReadonlyArray<B>)[]): B[]; }'.
3131
!!! error TS2322: Type 'A[]' is not assignable to type 'B[]'.
3232
!!! error TS2322: Type 'A' is not assignable to type 'B'.
3333
!!! error TS2322: Property 'b' is missing in type 'A'.
@@ -39,6 +39,6 @@ tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(18,1): error T
3939
~~~
4040
!!! error TS2322: Type 'C<A>' is not assignable to type 'ReadonlyArray<B>'.
4141
!!! error TS2322: Types of property 'concat' are incompatible.
42-
!!! error TS2322: Type '{ (...items: A[][]): A[]; (...items: (A | A[])[]): A[]; }' is not assignable to type '{ (...items: B[][]): B[]; (...items: (B | B[])[]): B[]; }'.
42+
!!! error TS2322: Type '{ (...items: ReadonlyArray<A>[]): A[]; (...items: (A | ReadonlyArray<A>)[]): A[]; }' is not assignable to type '{ (...items: ReadonlyArray<B>[]): B[]; (...items: (B | ReadonlyArray<B>)[]): B[]; }'.
4343
!!! error TS2322: Type 'A[]' is not assignable to type 'B[]'.
4444

tests/baselines/reference/concatError.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ fa = fa.concat([0]);
1515
>fa = fa.concat([0]) : number[]
1616
>fa : number[]
1717
>fa.concat([0]) : number[]
18-
>fa.concat : { (...items: number[][]): number[]; (...items: (number | number[])[]): number[]; }
18+
>fa.concat : { (...items: ReadonlyArray<number>[]): number[]; (...items: (number | ReadonlyArray<number>)[]): number[]; }
1919
>fa : number[]
20-
>concat : { (...items: number[][]): number[]; (...items: (number | number[])[]): number[]; }
20+
>concat : { (...items: ReadonlyArray<number>[]): number[]; (...items: (number | ReadonlyArray<number>)[]): number[]; }
2121
>[0] : number[]
2222
>0 : 0
2323

2424
fa = fa.concat(0);
2525
>fa = fa.concat(0) : number[]
2626
>fa : number[]
2727
>fa.concat(0) : number[]
28-
>fa.concat : { (...items: number[][]): number[]; (...items: (number | number[])[]): number[]; }
28+
>fa.concat : { (...items: ReadonlyArray<number>[]): number[]; (...items: (number | ReadonlyArray<number>)[]): number[]; }
2929
>fa : number[]
30-
>concat : { (...items: number[][]): number[]; (...items: (number | number[])[]): number[]; }
30+
>concat : { (...items: ReadonlyArray<number>[]): number[]; (...items: (number | ReadonlyArray<number>)[]): number[]; }
3131
>0 : 0
3232

3333

tests/baselines/reference/concatTuples.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ ijs = ijs.concat([[3, 4], [5, 6]]);
1010
>ijs = ijs.concat([[3, 4], [5, 6]]) : [number, number][]
1111
>ijs : [number, number][]
1212
>ijs.concat([[3, 4], [5, 6]]) : [number, number][]
13-
>ijs.concat : { (...items: [number, number][][]): [number, number][]; (...items: ([number, number] | [number, number][])[]): [number, number][]; }
13+
>ijs.concat : { (...items: ReadonlyArray<[number, number]>[]): [number, number][]; (...items: ([number, number] | ReadonlyArray<[number, number]>)[]): [number, number][]; }
1414
>ijs : [number, number][]
15-
>concat : { (...items: [number, number][][]): [number, number][]; (...items: ([number, number] | [number, number][])[]): [number, number][]; }
15+
>concat : { (...items: ReadonlyArray<[number, number]>[]): [number, number][]; (...items: ([number, number] | ReadonlyArray<[number, number]>)[]): [number, number][]; }
1616
>[[3, 4], [5, 6]] : [number, number][]
1717
>[3, 4] : [number, number]
1818
>3 : 3

tests/baselines/reference/emitSkipsThisWithRestParameter.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ function rebase(fn: (base: any, ...args: any[]) => any): (...args: any[]) => any
1818
>apply : (this: Function, thisArg: any, argArray?: any) => any
1919
>this : any
2020
>[ this ].concat(args) : any[]
21-
>[ this ].concat : { (...items: any[][]): any[]; (...items: any[]): any[]; }
21+
>[ this ].concat : { (...items: ReadonlyArray<any>[]): any[]; (...items: any[]): any[]; }
2222
>[ this ] : any[]
2323
>this : any
24-
>concat : { (...items: any[][]): any[]; (...items: any[]): any[]; }
24+
>concat : { (...items: ReadonlyArray<any>[]): any[]; (...items: any[]): any[]; }
2525
>args : any[]
2626

2727
};

tests/baselines/reference/iteratorSpreadInArray6.errors.txt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
tests/cases/conformance/es6/spread/iteratorSpreadInArray6.ts(15,14): error TS2345: Argument of type 'symbol[]' is not assignable to parameter of type 'number | number[]'.
2-
Type 'symbol[]' is not assignable to type 'number[]'.
3-
Type 'symbol' is not assignable to type 'number'.
1+
tests/cases/conformance/es6/spread/iteratorSpreadInArray6.ts(15,14): error TS2345: Argument of type 'symbol[]' is not assignable to parameter of type 'number | ReadonlyArray<number>'.
2+
Type 'symbol[]' is not assignable to type 'ReadonlyArray<number>'.
3+
Types of property 'concat' are incompatible.
4+
Type '{ (...items: ReadonlyArray<symbol>[]): symbol[]; (...items: (symbol | ReadonlyArray<symbol>)[]): symbol[]; }' is not assignable to type '{ (...items: ReadonlyArray<number>[]): number[]; (...items: (number | ReadonlyArray<number>)[]): number[]; }'.
5+
Types of parameters 'items' and 'items' are incompatible.
6+
Type 'ReadonlyArray<number>' is not assignable to type 'ReadonlyArray<symbol>'.
7+
Type 'number' is not assignable to type 'symbol'.
48

59

610
==== tests/cases/conformance/es6/spread/iteratorSpreadInArray6.ts (1 errors) ====
@@ -20,6 +24,10 @@ tests/cases/conformance/es6/spread/iteratorSpreadInArray6.ts(15,14): error TS234
2024
var array: number[] = [0, 1];
2125
array.concat([...new SymbolIterator]);
2226
~~~~~~~~~~~~~~~~~~~~~~~
23-
!!! error TS2345: Argument of type 'symbol[]' is not assignable to parameter of type 'number | number[]'.
24-
!!! error TS2345: Type 'symbol[]' is not assignable to type 'number[]'.
25-
!!! error TS2345: Type 'symbol' is not assignable to type 'number'.
27+
!!! error TS2345: Argument of type 'symbol[]' is not assignable to parameter of type 'number | ReadonlyArray<number>'.
28+
!!! error TS2345: Type 'symbol[]' is not assignable to type 'ReadonlyArray<number>'.
29+
!!! error TS2345: Types of property 'concat' are incompatible.
30+
!!! error TS2345: Type '{ (...items: ReadonlyArray<symbol>[]): symbol[]; (...items: (symbol | ReadonlyArray<symbol>)[]): symbol[]; }' is not assignable to type '{ (...items: ReadonlyArray<number>[]): number[]; (...items: (number | ReadonlyArray<number>)[]): number[]; }'.
31+
!!! error TS2345: Types of parameters 'items' and 'items' are incompatible.
32+
!!! error TS2345: Type 'ReadonlyArray<number>' is not assignable to type 'ReadonlyArray<symbol>'.
33+
!!! error TS2345: Type 'number' is not assignable to type 'symbol'.

tests/baselines/reference/iteratorSpreadInArray7.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ var array: symbol[];
3535

3636
array.concat([...new SymbolIterator]);
3737
>array.concat([...new SymbolIterator]) : symbol[]
38-
>array.concat : { (...items: symbol[][]): symbol[]; (...items: (symbol | symbol[])[]): symbol[]; }
38+
>array.concat : { (...items: ReadonlyArray<symbol>[]): symbol[]; (...items: (symbol | ReadonlyArray<symbol>)[]): symbol[]; }
3939
>array : symbol[]
40-
>concat : { (...items: symbol[][]): symbol[]; (...items: (symbol | symbol[])[]): symbol[]; }
40+
>concat : { (...items: ReadonlyArray<symbol>[]): symbol[]; (...items: (symbol | ReadonlyArray<symbol>)[]): symbol[]; }
4141
>[...new SymbolIterator] : symbol[]
4242
>...new SymbolIterator : symbol
4343
>new SymbolIterator : SymbolIterator

tests/baselines/reference/staticAnonymousTypeNotReferencingTypeParameter.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,9 @@ class ListWrapper {
348348
>a : any[]
349349
>b : any[]
350350
>a.concat(b) : any[]
351-
>a.concat : { (...items: any[][]): any[]; (...items: any[]): any[]; }
351+
>a.concat : { (...items: ReadonlyArray<any>[]): any[]; (...items: any[]): any[]; }
352352
>a : any[]
353-
>concat : { (...items: any[][]): any[]; (...items: any[]): any[]; }
353+
>concat : { (...items: ReadonlyArray<any>[]): any[]; (...items: any[]): any[]; }
354354
>b : any[]
355355

356356
static insert<T>(dit: typeof ListWrapper, list: T[], index: number, value: T) { list.splice(index, 0, value); }

0 commit comments

Comments
 (0)