Skip to content
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

Array.prototype.concat definition improvement #25716

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ interface ReadonlyArray<T> {
* Combines two or more arrays.
* @param items Additional items to add to the end of array1.
*/
concat(...items: ConcatArray<T>[]): T[];
concat<U>(...items: (ConcatArray<T> | ConcatArray<U>)[]): (T | U)[];
/**
* Combines two or more arrays.
* @param items Additional items to add to the end of array1.
Expand Down Expand Up @@ -1198,7 +1198,7 @@ interface Array<T> {
* Combines two or more arrays.
* @param items Additional items to add to the end of array1.
*/
concat(...items: ConcatArray<T>[]): T[];
concat<U>(...items: (ConcatArray<T> | ConcatArray<U>)[]): (T | U)[];
/**
* Combines two or more arrays.
* @param items Additional items to add to the end of array1.
Expand Down
12 changes: 6 additions & 6 deletions tests/baselines/reference/arrayConcat2.types
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ var a: string[] = [];

a.concat("hello", 'world');
>a.concat("hello", 'world') : string[]
>a.concat : { (...items: ConcatArray<string>[]): string[]; (...items: (string | ConcatArray<string>)[]): string[]; }
>a.concat : { <U>(...items: (ConcatArray<string> | ConcatArray<U>)[]): (string | U)[]; (...items: (string | ConcatArray<string>)[]): string[]; }
>a : string[]
>concat : { (...items: ConcatArray<string>[]): string[]; (...items: (string | ConcatArray<string>)[]): string[]; }
>concat : { <U>(...items: (ConcatArray<string> | ConcatArray<U>)[]): (string | U)[]; (...items: (string | ConcatArray<string>)[]): string[]; }
>"hello" : "hello"
>'world' : "world"

a.concat('Hello');
>a.concat('Hello') : string[]
>a.concat : { (...items: ConcatArray<string>[]): string[]; (...items: (string | ConcatArray<string>)[]): string[]; }
>a.concat : { <U>(...items: (ConcatArray<string> | ConcatArray<U>)[]): (string | U)[]; (...items: (string | ConcatArray<string>)[]): string[]; }
>a : string[]
>concat : { (...items: ConcatArray<string>[]): string[]; (...items: (string | ConcatArray<string>)[]): string[]; }
>concat : { <U>(...items: (ConcatArray<string> | ConcatArray<U>)[]): (string | U)[]; (...items: (string | ConcatArray<string>)[]): string[]; }
>'Hello' : "Hello"

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

b.concat('hello');
>b.concat('hello') : string[]
>b.concat : { (...items: ConcatArray<string>[]): string[]; (...items: (string | ConcatArray<string>)[]): string[]; }
>b.concat : { <U>(...items: (ConcatArray<string> | ConcatArray<U>)[]): (string | U)[]; (...items: (string | ConcatArray<string>)[]): string[]; }
>b : string[]
>concat : { (...items: ConcatArray<string>[]): string[]; (...items: (string | ConcatArray<string>)[]): string[]; }
>concat : { <U>(...items: (ConcatArray<string> | ConcatArray<U>)[]): (string | U)[]; (...items: (string | ConcatArray<string>)[]): string[]; }
>'hello' : "hello"

6 changes: 3 additions & 3 deletions tests/baselines/reference/arrayConcat3.types
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ function doStuff<T extends object, T1 extends T>(a: Array<Fn<T>>, b: Array<Fn<T1
>b : Fn<T1>[]

b.concat(a);
>b.concat(a) : Fn<T1>[]
>b.concat : { (...items: ConcatArray<Fn<T1>>[]): Fn<T1>[]; (...items: (Fn<T1> | ConcatArray<Fn<T1>>)[]): Fn<T1>[]; }
>b.concat(a) : (Fn<T> | Fn<T1>)[]
>b.concat : { <U>(...items: (ConcatArray<Fn<T1>> | ConcatArray<U>)[]): (Fn<T1> | U)[]; (...items: (Fn<T1> | ConcatArray<Fn<T1>>)[]): Fn<T1>[]; }
>b : Fn<T1>[]
>concat : { (...items: ConcatArray<Fn<T1>>[]): Fn<T1>[]; (...items: (Fn<T1> | ConcatArray<Fn<T1>>)[]): Fn<T1>[]; }
>concat : { <U>(...items: (ConcatArray<Fn<T1>> | ConcatArray<U>)[]): (Fn<T1> | U)[]; (...items: (Fn<T1> | ConcatArray<Fn<T1>>)[]): Fn<T1>[]; }
>a : Fn<T>[]
}

4 changes: 2 additions & 2 deletions tests/baselines/reference/arrayConcatMap.types
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ var x = [].concat([{ a: 1 }], [{ a: 2 }])
>[].concat([{ a: 1 }], [{ a: 2 }]) .map(b => b.a) : any[]
>[].concat([{ a: 1 }], [{ a: 2 }]) .map : <U>(callbackfn: (value: any, index: number, array: any[]) => U, thisArg?: any) => U[]
>[].concat([{ a: 1 }], [{ a: 2 }]) : any[]
>[].concat : { (...items: ConcatArray<any>[]): any[]; (...items: any[]): any[]; }
>[].concat : { <U>(...items: (ConcatArray<any> | ConcatArray<U>)[]): any[]; (...items: any[]): any[]; }
>[] : undefined[]
>concat : { (...items: ConcatArray<any>[]): any[]; (...items: any[]): any[]; }
>concat : { <U>(...items: (ConcatArray<any> | ConcatArray<U>)[]): any[]; (...items: any[]): any[]; }
>[{ a: 1 }] : { a: number; }[]
>{ a: 1 } : { a: number; }
>a : number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(13,1): error T
Property 'b' is missing in type 'A'.
tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(18,1): error TS2322: Type 'C<A>' is not assignable to type 'ReadonlyArray<B>'.
Types of property 'concat' are incompatible.
Type '{ (...items: ConcatArray<A>[]): A[]; (...items: (A | ConcatArray<A>)[]): A[]; }' is not assignable to type '{ (...items: ConcatArray<B>[]): B[]; (...items: (B | ConcatArray<B>)[]): B[]; }'.
Type 'A[]' is not assignable to type 'B[]'.
Type 'A' is not assignable to type 'B'.
Type '{ <U>(...items: (ConcatArray<A> | ConcatArray<U>)[]): (A | U)[]; (...items: (A | ConcatArray<A>)[]): A[]; }' is not assignable to type '{ <U>(...items: (ConcatArray<B> | ConcatArray<U>)[]): (B | U)[]; (...items: (B | ConcatArray<B>)[]): B[]; }'.
Types of parameters 'items' and 'items' are incompatible.
Type 'B | ConcatArray<B>' is not assignable to type 'ConcatArray<any> | ConcatArray<A>'.
Type 'B' is not assignable to type 'ConcatArray<any> | ConcatArray<A>'.
Type 'B' is not assignable to type 'ConcatArray<A>'.
Property 'length' is missing in type 'B'.


==== tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts (2 errors) ====
Expand Down Expand Up @@ -34,7 +37,10 @@ tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(18,1): error T
~~~
!!! error TS2322: Type 'C<A>' is not assignable to type 'ReadonlyArray<B>'.
!!! error TS2322: Types of property 'concat' are incompatible.
!!! error TS2322: Type '{ (...items: ConcatArray<A>[]): A[]; (...items: (A | ConcatArray<A>)[]): A[]; }' is not assignable to type '{ (...items: ConcatArray<B>[]): B[]; (...items: (B | ConcatArray<B>)[]): B[]; }'.
!!! error TS2322: Type 'A[]' is not assignable to type 'B[]'.
!!! error TS2322: Type 'A' is not assignable to type 'B'.
!!! error TS2322: Type '{ <U>(...items: (ConcatArray<A> | ConcatArray<U>)[]): (A | U)[]; (...items: (A | ConcatArray<A>)[]): A[]; }' is not assignable to type '{ <U>(...items: (ConcatArray<B> | ConcatArray<U>)[]): (B | U)[]; (...items: (B | ConcatArray<B>)[]): B[]; }'.
!!! error TS2322: Types of parameters 'items' and 'items' are incompatible.
!!! error TS2322: Type 'B | ConcatArray<B>' is not assignable to type 'ConcatArray<any> | ConcatArray<A>'.
!!! error TS2322: Type 'B' is not assignable to type 'ConcatArray<any> | ConcatArray<A>'.
!!! error TS2322: Type 'B' is not assignable to type 'ConcatArray<A>'.
!!! error TS2322: Property 'length' is missing in type 'B'.

8 changes: 4 additions & 4 deletions tests/baselines/reference/concatError.types
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ fa = fa.concat([0]);
>fa = fa.concat([0]) : number[]
>fa : number[]
>fa.concat([0]) : number[]
>fa.concat : { (...items: ConcatArray<number>[]): number[]; (...items: (number | ConcatArray<number>)[]): number[]; }
>fa.concat : { <U>(...items: (ConcatArray<number> | ConcatArray<U>)[]): (number | U)[]; (...items: (number | ConcatArray<number>)[]): number[]; }
>fa : number[]
>concat : { (...items: ConcatArray<number>[]): number[]; (...items: (number | ConcatArray<number>)[]): number[]; }
>concat : { <U>(...items: (ConcatArray<number> | ConcatArray<U>)[]): (number | U)[]; (...items: (number | ConcatArray<number>)[]): number[]; }
>[0] : number[]
>0 : 0

fa = fa.concat(0);
>fa = fa.concat(0) : number[]
>fa : number[]
>fa.concat(0) : number[]
>fa.concat : { (...items: ConcatArray<number>[]): number[]; (...items: (number | ConcatArray<number>)[]): number[]; }
>fa.concat : { <U>(...items: (ConcatArray<number> | ConcatArray<U>)[]): (number | U)[]; (...items: (number | ConcatArray<number>)[]): number[]; }
>fa : number[]
>concat : { (...items: ConcatArray<number>[]): number[]; (...items: (number | ConcatArray<number>)[]): number[]; }
>concat : { <U>(...items: (ConcatArray<number> | ConcatArray<U>)[]): (number | U)[]; (...items: (number | ConcatArray<number>)[]): number[]; }
>0 : 0


Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/concatTuples.types
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ ijs = ijs.concat([[3, 4], [5, 6]]);
>ijs = ijs.concat([[3, 4], [5, 6]]) : [number, number][]
>ijs : [number, number][]
>ijs.concat([[3, 4], [5, 6]]) : [number, number][]
>ijs.concat : { (...items: ConcatArray<[number, number]>[]): [number, number][]; (...items: ([number, number] | ConcatArray<[number, number]>)[]): [number, number][]; }
>ijs.concat : { <U>(...items: (ConcatArray<[number, number]> | ConcatArray<U>)[]): ([number, number] | U)[]; (...items: ([number, number] | ConcatArray<[number, number]>)[]): [number, number][]; }
>ijs : [number, number][]
>concat : { (...items: ConcatArray<[number, number]>[]): [number, number][]; (...items: ([number, number] | ConcatArray<[number, number]>)[]): [number, number][]; }
>concat : { <U>(...items: (ConcatArray<[number, number]> | ConcatArray<U>)[]): ([number, number] | U)[]; (...items: ([number, number] | ConcatArray<[number, number]>)[]): [number, number][]; }
>[[3, 4], [5, 6]] : [number, number][]
>[3, 4] : [number, number]
>3 : 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ export default class Operation {
>result = (result || []).concat(innerResult) : IValidationError[]
>result : IValidationError[] | null
>(result || []).concat(innerResult) : IValidationError[]
>(result || []).concat : { (...items: ConcatArray<IValidationError>[]): IValidationError[]; (...items: (IValidationError | ConcatArray<IValidationError>)[]): IValidationError[]; }
>(result || []).concat : { <U>(...items: (ConcatArray<IValidationError> | ConcatArray<U>)[]): (IValidationError | U)[]; (...items: (IValidationError | ConcatArray<IValidationError>)[]): IValidationError[]; }
>(result || []) : IValidationError[]
>result || [] : IValidationError[]
>result : IValidationError[] | null
>[] : never[]
>concat : { (...items: ConcatArray<IValidationError>[]): IValidationError[]; (...items: (IValidationError | ConcatArray<IValidationError>)[]): IValidationError[]; }
>concat : { <U>(...items: (ConcatArray<IValidationError> | ConcatArray<U>)[]): (IValidationError | U)[]; (...items: (IValidationError | ConcatArray<IValidationError>)[]): IValidationError[]; }
>innerResult : any
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ function rebase(fn: (base: any, ...args: any[]) => any): (...args: any[]) => any
>apply : (this: Function, thisArg: any, argArray?: any) => any
>this : any
>[ this ].concat(args) : any[]
>[ this ].concat : { (...items: ConcatArray<any>[]): any[]; (...items: any[]): any[]; }
>[ this ].concat : { <U>(...items: (ConcatArray<any> | ConcatArray<U>)[]): any[]; (...items: any[]): any[]; }
>[ this ] : any[]
>this : any
>concat : { (...items: ConcatArray<any>[]): any[]; (...items: any[]): any[]; }
>concat : { <U>(...items: (ConcatArray<any> | ConcatArray<U>)[]): any[]; (...items: any[]): any[]; }
>args : any[]

};
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/intersectionTypeInference3.types
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ declare const b: Set<A>;
const c1 = Array.from(a).concat(Array.from(b));
>c1 : Nominal<"A", string>[]
>Array.from(a).concat(Array.from(b)) : Nominal<"A", string>[]
>Array.from(a).concat : { (...items: ConcatArray<Nominal<"A", string>>[]): Nominal<"A", string>[]; (...items: (Nominal<"A", string> | ConcatArray<Nominal<"A", string>>)[]): Nominal<"A", string>[]; }
>Array.from(a).concat : { <U>(...items: (ConcatArray<Nominal<"A", string>> | ConcatArray<U>)[]): (Nominal<"A", string> | U)[]; (...items: (Nominal<"A", string> | ConcatArray<Nominal<"A", string>>)[]): Nominal<"A", string>[]; }
>Array.from(a) : Nominal<"A", string>[]
>Array.from : { <T>(arrayLike: ArrayLike<T>): T[]; <T, U>(arrayLike: ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; <T>(iterable: Iterable<T> | ArrayLike<T>): T[]; <T, U>(iterable: Iterable<T> | ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; }
>Array : ArrayConstructor
>from : { <T>(arrayLike: ArrayLike<T>): T[]; <T, U>(arrayLike: ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; <T>(iterable: Iterable<T> | ArrayLike<T>): T[]; <T, U>(iterable: Iterable<T> | ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; }
>a : Set<Nominal<"A", string>>
>concat : { (...items: ConcatArray<Nominal<"A", string>>[]): Nominal<"A", string>[]; (...items: (Nominal<"A", string> | ConcatArray<Nominal<"A", string>>)[]): Nominal<"A", string>[]; }
>concat : { <U>(...items: (ConcatArray<Nominal<"A", string>> | ConcatArray<U>)[]): (Nominal<"A", string> | U)[]; (...items: (Nominal<"A", string> | ConcatArray<Nominal<"A", string>>)[]): Nominal<"A", string>[]; }
>Array.from(b) : Nominal<"A", string>[]
>Array.from : { <T>(arrayLike: ArrayLike<T>): T[]; <T, U>(arrayLike: ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; <T>(iterable: Iterable<T> | ArrayLike<T>): T[]; <T, U>(iterable: Iterable<T> | ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; }
>Array : ArrayConstructor
Expand Down
31 changes: 0 additions & 31 deletions tests/baselines/reference/iteratorSpreadInArray6.errors.txt

This file was deleted.

6 changes: 3 additions & 3 deletions tests/baselines/reference/iteratorSpreadInArray6.types
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ var array: number[] = [0, 1];
>1 : 1

array.concat([...new SymbolIterator]);
>array.concat([...new SymbolIterator]) : any
>array.concat : { (...items: ConcatArray<number>[]): number[]; (...items: (number | ConcatArray<number>)[]): number[]; }
>array.concat([...new SymbolIterator]) : (number | symbol)[]
>array.concat : { <U>(...items: (ConcatArray<number> | ConcatArray<U>)[]): (number | U)[]; (...items: (number | ConcatArray<number>)[]): number[]; }
>array : number[]
>concat : { (...items: ConcatArray<number>[]): number[]; (...items: (number | ConcatArray<number>)[]): number[]; }
>concat : { <U>(...items: (ConcatArray<number> | ConcatArray<U>)[]): (number | U)[]; (...items: (number | ConcatArray<number>)[]): number[]; }
>[...new SymbolIterator] : symbol[]
>...new SymbolIterator : symbol
>new SymbolIterator : SymbolIterator
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/iteratorSpreadInArray7.types
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ var array: symbol[];

array.concat([...new SymbolIterator]);
>array.concat([...new SymbolIterator]) : symbol[]
>array.concat : { (...items: ConcatArray<symbol>[]): symbol[]; (...items: (symbol | ConcatArray<symbol>)[]): symbol[]; }
>array.concat : { <U>(...items: (ConcatArray<symbol> | ConcatArray<U>)[]): (symbol | U)[]; (...items: (symbol | ConcatArray<symbol>)[]): symbol[]; }
>array : symbol[]
>concat : { (...items: ConcatArray<symbol>[]): symbol[]; (...items: (symbol | ConcatArray<symbol>)[]): symbol[]; }
>concat : { <U>(...items: (ConcatArray<symbol> | ConcatArray<U>)[]): (symbol | U)[]; (...items: (symbol | ConcatArray<symbol>)[]): symbol[]; }
>[...new SymbolIterator] : symbol[]
>...new SymbolIterator : symbol
>new SymbolIterator : SymbolIterator
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/mappedTypesArraysTuples.types
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ function f2<T extends any[]>(a: Boxified<T>) {
let y: Box<any>[] = a.concat(a);
>y : Box<any>[]
>a.concat(a) : Box<any>[]
>a.concat : { (...items: ConcatArray<Box<any>>[]): Box<any>[]; (...items: (Box<any> | ConcatArray<Box<any>>)[]): Box<any>[]; }
>a.concat : { <U>(...items: (ConcatArray<Box<any>> | ConcatArray<U>)[]): (Box<any> | U)[]; (...items: (Box<any> | ConcatArray<Box<any>>)[]): Box<any>[]; }
>a : Boxified<T>
>concat : { (...items: ConcatArray<Box<any>>[]): Box<any>[]; (...items: (Box<any> | ConcatArray<Box<any>>)[]): Box<any>[]; }
>concat : { <U>(...items: (ConcatArray<Box<any>> | ConcatArray<U>)[]): (Box<any> | U)[]; (...items: (Box<any> | ConcatArray<Box<any>>)[]): Box<any>[]; }
>a : Boxified<T>
}

Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/parserRealSource4.types
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,14 @@ module TypeScript {

return this.primaryTable.getAllKeys().concat(this.secondaryTable.getAllKeys());
>this.primaryTable.getAllKeys().concat(this.secondaryTable.getAllKeys()) : string[]
>this.primaryTable.getAllKeys().concat : { (...items: ConcatArray<string>[]): string[]; (...items: (string | ConcatArray<string>)[]): string[]; }
>this.primaryTable.getAllKeys().concat : { <U>(...items: (ConcatArray<string> | ConcatArray<U>)[]): (string | U)[]; (...items: (string | ConcatArray<string>)[]): string[]; }
>this.primaryTable.getAllKeys() : string[]
>this.primaryTable.getAllKeys : () => string[]
>this.primaryTable : IHashTable
>this : this
>primaryTable : IHashTable
>getAllKeys : () => string[]
>concat : { (...items: ConcatArray<string>[]): string[]; (...items: (string | ConcatArray<string>)[]): string[]; }
>concat : { <U>(...items: (ConcatArray<string> | ConcatArray<U>)[]): (string | U)[]; (...items: (string | ConcatArray<string>)[]): string[]; }
>this.secondaryTable.getAllKeys() : string[]
>this.secondaryTable.getAllKeys : () => string[]
>this.secondaryTable : IHashTable
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/parserharness.types
Original file line number Diff line number Diff line change
Expand Up @@ -4775,9 +4775,9 @@ module Harness {
>lines = lines.concat(v.file.lines) : any[]
>lines : any[]
>lines.concat(v.file.lines) : any[]
>lines.concat : { (...items: ConcatArray<any>[]): any[]; (...items: any[]): any[]; }
>lines.concat : { <U>(...items: (ConcatArray<any> | ConcatArray<U>)[]): any[]; (...items: any[]): any[]; }
>lines : any[]
>concat : { (...items: ConcatArray<any>[]): any[]; (...items: any[]): any[]; }
>concat : { <U>(...items: (ConcatArray<any> | ConcatArray<U>)[]): any[]; (...items: any[]): any[]; }
>v.file.lines : string[]
>v.file : WriterAggregator
>v : { filename: string; file: WriterAggregator; }
Expand Down
Loading