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

🤖 User test baselines have changed for patch-13 #3

Open
wants to merge 3 commits into
base: patch-13
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4687,6 +4687,7 @@ namespace FourSlashInterface {
varEntry("JSON"),
interfaceEntry("ReadonlyArray"),
interfaceEntry("ConcatArray"),
typeEntry("ConcatFlatten"),
varEntry("Array"),
interfaceEntry("ArrayConstructor"),
interfaceEntry("TypedPropertyDescriptor"),
Expand Down
184 changes: 22 additions & 162 deletions src/lib/es2019.array.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
type Flatten<T> = T extends undefined ? T : T extends readonly (infer U)[] ? U : T;

interface ReadonlyArray<T> {

/**
Expand All @@ -10,106 +12,23 @@ interface ReadonlyArray<T> {
* @param thisArg An object to which the this keyword can refer in the callback function. If
* thisArg is omitted, undefined is used as the this value.
*/
flatMap<U, This = undefined> (
callback: (this: This, value: T, index: number, array: T[]) => U | ReadonlyArray<U>,
thisArg?: This
): U[]


/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
* specified depth.
*
* @param depth The maximum recursion depth
*/
flat<U>(this:
ReadonlyArray<U[][][][]> |

ReadonlyArray<ReadonlyArray<U[][][]>> |
ReadonlyArray<ReadonlyArray<U[][]>[]> |
ReadonlyArray<ReadonlyArray<U[]>[][]> |
ReadonlyArray<ReadonlyArray<U>[][][]> |

ReadonlyArray<ReadonlyArray<ReadonlyArray<U[][]>>> |
ReadonlyArray<ReadonlyArray<ReadonlyArray<U>[][]>> |
ReadonlyArray<ReadonlyArray<ReadonlyArray<U>>[][]> |
ReadonlyArray<ReadonlyArray<ReadonlyArray<U>[]>[]> |
ReadonlyArray<ReadonlyArray<ReadonlyArray<U[]>>[]> |
ReadonlyArray<ReadonlyArray<ReadonlyArray<U[]>[]>> |

ReadonlyArray<ReadonlyArray<ReadonlyArray<ReadonlyArray<U[]>>>> |
ReadonlyArray<ReadonlyArray<ReadonlyArray<ReadonlyArray<U>[]>>> |
ReadonlyArray<ReadonlyArray<ReadonlyArray<ReadonlyArray<U>>[]>> |
ReadonlyArray<ReadonlyArray<ReadonlyArray<ReadonlyArray<U>>>[]> |

ReadonlyArray<ReadonlyArray<ReadonlyArray<ReadonlyArray<ReadonlyArray<U>>>>>,
depth: 4): U[];

/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
* specified depth.
*
* @param depth The maximum recursion depth
*/
flat<U>(this:
ReadonlyArray<U[][][]> |

ReadonlyArray<ReadonlyArray<U>[][]> |
ReadonlyArray<ReadonlyArray<U[]>[]> |
ReadonlyArray<ReadonlyArray<U[][]>> |

ReadonlyArray<ReadonlyArray<ReadonlyArray<U[]>>> |
ReadonlyArray<ReadonlyArray<ReadonlyArray<U>[]>> |
ReadonlyArray<ReadonlyArray<ReadonlyArray<U>>[]> |

ReadonlyArray<ReadonlyArray<ReadonlyArray<ReadonlyArray<U>>>>,
depth: 3): U[];

/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
* specified depth.
*
* @param depth The maximum recursion depth
*/
flat<U>(this:
ReadonlyArray<U[][]> |

ReadonlyArray<ReadonlyArray<U[]>> |
ReadonlyArray<ReadonlyArray<U>[]> |

ReadonlyArray<ReadonlyArray<ReadonlyArray<U>>>,
depth: 2): U[];
flatMap<U> (
callbackfn: (value: T, index: number, array: readonly T[]) => U,
thisArg?: any
): Flatten<U>[];

/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
* specified depth.
*
* @param depth The maximum recursion depth
*/
flat<U>(this:
ReadonlyArray<U[]> |
ReadonlyArray<ReadonlyArray<U>>,
depth?: 1
): U[];

/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
* specified depth.
*
* @param depth The maximum recursion depth
*/
flat<U>(this:
ReadonlyArray<U>,
depth: 0
): U[];

/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
* specified depth. If no depth is provided, flat method defaults to the depth of 1.
*
* @param depth The maximum recursion depth
*/
flat<U>(depth?: number): any[];
flat(depth: 4): Flatten<Flatten<Flatten<Flatten<T>>>>[];
flat(depth: 3): Flatten<Flatten<Flatten<T>>>[];
flat(depth: 2): Flatten<Flatten<T>>[];
flat(depth?: 1): Flatten<T>[];
flat(depth: 0): T[];
flat(depth: number): any[];
}

interface Array<T> {
Expand All @@ -124,80 +43,21 @@ interface Array<T> {
* @param thisArg An object to which the this keyword can refer in the callback function. If
* thisArg is omitted, undefined is used as the this value.
*/
flatMap<U, This = undefined> (
callback: (this: This, value: T, index: number, array: T[]) => U | ReadonlyArray<U>,
thisArg?: This
): U[]

/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
* specified depth.
*
* @param depth The maximum recursion depth
*/
flat<U>(this: U[][][][][][][][], depth: 7): U[];

/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
* specified depth.
*
* @param depth The maximum recursion depth
*/
flat<U>(this: U[][][][][][][], depth: 6): U[];

/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
* specified depth.
*
* @param depth The maximum recursion depth
*/
flat<U>(this: U[][][][][][], depth: 5): U[];

/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
* specified depth.
*
* @param depth The maximum recursion depth
*/
flat<U>(this: U[][][][][], depth: 4): U[];

/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
* specified depth.
*
* @param depth The maximum recursion depth
*/
flat<U>(this: U[][][][], depth: 3): U[];
flatMap<U> (
callbackfn: (value: T, index: number, array: T[]) => U,
thisArg?: any
): Flatten<U>[];

/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
* specified depth.
*
* @param depth The maximum recursion depth
*/
flat<U>(this: U[][][], depth: 2): U[];

/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
* specified depth.
*
* @param depth The maximum recursion depth
*/
flat<U>(this: U[][], depth?: 1): U[];

/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
* specified depth.
*
* @param depth The maximum recursion depth
*/
flat<U>(this: U[], depth: 0): U[];

/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
* specified depth. If no depth is provided, flat method defaults to the depth of 1.
*
* @param depth The maximum recursion depth
*/
flat<U>(depth?: number): any[];
flat(depth: 4): Flatten<Flatten<Flatten<Flatten<T>>>>[];
flat(depth: 3): Flatten<Flatten<Flatten<T>>>[];
flat(depth: 2): Flatten<Flatten<T>>[];
flat(depth?: 1): Flatten<T>[];
flat(depth: 0): T[];
flat(depth: number): any[];
}
13 changes: 3 additions & 10 deletions src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1081,11 +1081,7 @@ interface ReadonlyArray<T> {
* @param items Additional items to add to the end of array1.
*/
concat(...items: ConcatArray<T>[]): T[];
/**
* Combines two or more arrays.
* @param items Additional items to add to the end of array1.
*/
concat(...items: (T | ConcatArray<T>)[]): T[];
concat<U extends any[]>(...items: U): (T | ConcatFlatten<U[number]>)[];
/**
* Adds all the elements of an array separated by the specified separator string.
* @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.
Expand Down Expand Up @@ -1187,6 +1183,7 @@ interface ConcatArray<T> {
join(separator?: string): string;
slice(start?: number, end?: number): T[];
}
type ConcatFlatten<T> = T extends undefined ? T : T extends ConcatArray<infer U> ? U : T;

interface Array<T> {
/**
Expand Down Expand Up @@ -1215,11 +1212,7 @@ interface Array<T> {
* @param items Additional items to add to the end of array1.
*/
concat(...items: ConcatArray<T>[]): T[];
/**
* Combines two or more arrays.
* @param items Additional items to add to the end of array1.
*/
concat(...items: (T | ConcatArray<T>)[]): T[];
concat<U extends any[]>(...items: U): (T | ConcatFlatten<U[number]>)[];
/**
* Adds all the elements of an array separated by the specified separator string.
* @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.
Expand Down
23 changes: 23 additions & 0 deletions tests/baselines/reference/arrayConcat2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ a.concat('Hello');

var b = new Array<string>();
b.concat('hello');

const expected: undefined = undefined as ConcatFlatten<undefined>;

// #19535

const [x] = (undefined as unknown as number[][]).concat([1]);
x == 1;

// #26378

[1].concat(['']);

// #26976

[].concat([1]);


//// [arrayConcat2.js]
Expand All @@ -14,3 +29,11 @@ a.concat("hello", 'world');
a.concat('Hello');
var b = new Array();
b.concat('hello');
var expected = undefined;
// #19535
var x = undefined.concat([1])[0];
x == 1;
// #26378
[1].concat(['']);
// #26976
[].concat([1]);
28 changes: 28 additions & 0 deletions tests/baselines/reference/arrayConcat2.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,31 @@ b.concat('hello');
>b : Symbol(b, Decl(arrayConcat2.ts, 5, 3))
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))

const expected: undefined = undefined as ConcatFlatten<undefined>;
>expected : Symbol(expected, Decl(arrayConcat2.ts, 8, 5))
>undefined : Symbol(undefined)
>ConcatFlatten : Symbol(ConcatFlatten, Decl(lib.es5.d.ts, --, --))

// #19535

const [x] = (undefined as unknown as number[][]).concat([1]);
>x : Symbol(x, Decl(arrayConcat2.ts, 12, 7))
>(undefined as unknown as number[][]).concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>undefined : Symbol(undefined)
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))

x == 1;
>x : Symbol(x, Decl(arrayConcat2.ts, 12, 7))

// #26378

[1].concat(['']);
>[1].concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))

// #26976

[].concat([1]);
>[].concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))

Loading