From 367b6d6593620d8d7368548b02a64844c94ec94c Mon Sep 17 00:00:00 2001 From: crowlkats Date: Mon, 31 Oct 2022 20:31:28 +0100 Subject: [PATCH 1/6] feat(cli/dts): add typings for Change Array by copy proposal --- cli/dts/lib.esnext.array.d.ts | 247 +++++++++++++++++++++++++++++++++- 1 file changed, 246 insertions(+), 1 deletion(-) diff --git a/cli/dts/lib.esnext.array.d.ts b/cli/dts/lib.esnext.array.d.ts index 76defb57e68133..bb53d95efd12a1 100644 --- a/cli/dts/lib.esnext.array.d.ts +++ b/cli/dts/lib.esnext.array.d.ts @@ -38,6 +38,38 @@ interface Array { * predicate. If it is not provided, undefined is used instead. */ findLastIndex(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): number; + + /** Copies and reverses the elements in an array.*/ + toReversed(): T[]; + + /** + * Copies and sorts an array. + * @param compareFn Function used to determine the order of the elements. It is expected to return + * a negative value if the first argument is less than the second argument, zero if they're equal, and a positive + * value otherwise. If omitted, the elements are sorted in ascending, ASCII character order. + * ```ts + * [11,2,22,1].sort((a, b) => a - b) + * ``` + */ + toSorted(compareFn?: (a: T, b: T) => number): T[]; + + /** + * Copies and elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. + * @param start The zero-based location in the array from which to start removing elements. + * @param deleteCount The number of elements to remove. + * @returns An array containing the elements that were deleted. + */ + toSpliced(start: number, deleteCount?: number): T[]; + /** + * Copies and removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. + * @param start The zero-based location in the array from which to start removing elements. + * @param deleteCount The number of elements to remove. + * @param items Elements to insert into the array in place of the deleted elements. + * @returns An array containing the elements that were deleted. + */ + toSpliced(start: number, deleteCount: number, ...items: T[]): T[]; + + with(index: number, value: any): any[]; } interface ReadonlyArray { @@ -52,7 +84,7 @@ interface ReadonlyArray { */ findLast(predicate: (this: void, value: T, index: number, obj: T[]) => value is S, thisArg?: any): S | undefined; findLast(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): T | undefined; - + /** * Returns the index of the last element in the array where predicate is true, and -1 * otherwise. @@ -63,6 +95,38 @@ interface ReadonlyArray { * predicate. If it is not provided, undefined is used instead. */ findLastIndex(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): number; + + /** Copies and reverses the elements in an array.*/ + toReversed(): T[]; + + /** + * Copies and sorts an array. + * @param compareFn Function used to determine the order of the elements. It is expected to return + * a negative value if the first argument is less than the second argument, zero if they're equal, and a positive + * value otherwise. If omitted, the elements are sorted in ascending, ASCII character order. + * ```ts + * [11,2,22,1].sort((a, b) => a - b) + * ``` + */ + toSorted(compareFn?: (a: T, b: T) => number): T[]; + + /** + * Copies and elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. + * @param start The zero-based location in the array from which to start removing elements. + * @param deleteCount The number of elements to remove. + * @returns An array containing the elements that were deleted. + */ + toSpliced(start: number, deleteCount?: number): T[]; + /** + * Copies and removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. + * @param start The zero-based location in the array from which to start removing elements. + * @param deleteCount The number of elements to remove. + * @param items Elements to insert into the array in place of the deleted elements. + * @returns An array containing the elements that were deleted. + */ + toSpliced(start: number, deleteCount: number, ...items: T[]): T[]; + + with(index: number, value: any): any[]; } interface Int8Array { @@ -87,6 +151,22 @@ interface Int8Array { * predicate. If it is not provided, undefined is used instead. */ findLastIndex(predicate: (value: number, index: number, obj: Int8Array) => boolean, thisArg?: any): number; + + /** Copies and reverses the elements in an array.*/ + toReversed(): Int8Array; + + /** + * Copies and sorts an array. + * @param compareFn Function used to determine the order of the elements. It is expected to return + * a negative value if first argument is less than second argument, zero if they're equal and a positive + * value otherwise. If omitted, the elements are sorted in ascending order. + * ```ts + * [11,2,22,1].sort((a, b) => a - b) + * ``` + */ + toSorted(compareFn?: (a: number, b: number) => number): Int8Array; + + with(index: number, value: number): Int8Array; } interface Uint8Array { @@ -111,6 +191,22 @@ interface Uint8Array { * predicate. If it is not provided, undefined is used instead. */ findLastIndex(predicate: (value: number, index: number, obj: Uint8Array) => boolean, thisArg?: any): number; + + /** Copies and reverses the elements in an array.*/ + toReversed(): Uint8Array; + + /** + * Copies and sorts an array. + * @param compareFn Function used to determine the order of the elements. It is expected to return + * a negative value if first argument is less than second argument, zero if they're equal and a positive + * value otherwise. If omitted, the elements are sorted in ascending order. + * ```ts + * [11,2,22,1].sort((a, b) => a - b) + * ``` + */ + toSorted(compareFn?: (a: number, b: number) => number): Uint8Array; + + with(index: number, value: number): Uint8Array; } interface Uint8ClampedArray { @@ -135,6 +231,22 @@ interface Uint8ClampedArray { * predicate. If it is not provided, undefined is used instead. */ findIndexLast(predicate: (value: number, index: number, obj: Uint8ClampedArray) => boolean, thisArg?: any): number; + + /** Copies and reverses the elements in an array.*/ + toReversed(): Uint8ClampedArray; + + /** + * Copies and sorts an array. + * @param compareFn Function used to determine the order of the elements. It is expected to return + * a negative value if first argument is less than second argument, zero if they're equal and a positive + * value otherwise. If omitted, the elements are sorted in ascending order. + * ```ts + * [11,2,22,1].sort((a, b) => a - b) + * ``` + */ + toSorted(compareFn?: (a: number, b: number) => number): Uint8ClampedArray; + + with(index: number, value: number): Uint8ClampedArray; } @@ -160,6 +272,23 @@ interface Int16Array { * predicate. If it is not provided, undefined is used instead. */ findIndexLast(predicate: (value: number, index: number, obj: Int16Array) => boolean, thisArg?: any): number; + + + /** Copies and reverses the elements in an array.*/ + toReversed(): Int16Array; + + /** + * Copies and sorts an array. + * @param compareFn Function used to determine the order of the elements. It is expected to return + * a negative value if first argument is less than second argument, zero if they're equal and a positive + * value otherwise. If omitted, the elements are sorted in ascending order. + * ```ts + * [11,2,22,1].sort((a, b) => a - b) + * ``` + */ + toSorted(compareFn?: (a: number, b: number) => number): Int16Array; + + with(index: number, value: number): Int16Array; } interface Uint16Array { @@ -184,6 +313,23 @@ interface Uint16Array { * predicate. If it is not provided, undefined is used instead. */ findIndexLast(predicate: (value: number, index: number, obj: Uint16Array) => boolean, thisArg?: any): number; + + + /** Copies and reverses the elements in an array.*/ + toReversed(): Uint16Array; + + /** + * Copies and sorts an array. + * @param compareFn Function used to determine the order of the elements. It is expected to return + * a negative value if first argument is less than second argument, zero if they're equal and a positive + * value otherwise. If omitted, the elements are sorted in ascending order. + * ```ts + * [11,2,22,1].sort((a, b) => a - b) + * ``` + */ + toSorted(compareFn?: (a: number, b: number) => number): Uint16Array; + + with(index: number, value: number): Uint16Array; } interface Int32Array { @@ -208,6 +354,22 @@ interface Int32Array { * predicate. If it is not provided, undefined is used instead. */ findIndexLast(predicate: (value: number, index: number, obj: Int32Array) => boolean, thisArg?: any): number; + + /** Copies and reverses the elements in an array.*/ + toReversed(): Int32Array; + + /** + * Copies and sorts an array. + * @param compareFn Function used to determine the order of the elements. It is expected to return + * a negative value if first argument is less than second argument, zero if they're equal and a positive + * value otherwise. If omitted, the elements are sorted in ascending order. + * ```ts + * [11,2,22,1].sort((a, b) => a - b) + * ``` + */ + toSorted(compareFn?: (a: number, b: number) => number): Int32Array; + + with(index: number, value: number): Int32Array; } interface Uint32Array { @@ -232,6 +394,22 @@ interface Uint32Array { * predicate. If it is not provided, undefined is used instead. */ findIndexLast(predicate: (value: number, index: number, obj: Uint32Array) => boolean, thisArg?: any): number; + + /** Copies and reverses the elements in an array.*/ + toReversed(): Uint32Array; + + /** + * Copies and sorts an array. + * @param compareFn Function used to determine the order of the elements. It is expected to return + * a negative value if first argument is less than second argument, zero if they're equal and a positive + * value otherwise. If omitted, the elements are sorted in ascending order. + * ```ts + * [11,2,22,1].sort((a, b) => a - b) + * ``` + */ + toSorted(compareFn?: (a: number, b: number) => number): Uint32Array; + + with(index: number, value: number): Uint32Array; } interface Float32Array { @@ -256,6 +434,23 @@ interface Float32Array { * predicate. If it is not provided, undefined is used instead. */ findIndexLast(predicate: (value: number, index: number, obj: Float32Array) => boolean, thisArg?: any): number; + + + /** Copies and reverses the elements in an array.*/ + toReversed(): Float32Array; + + /** + * Copies and sorts an array. + * @param compareFn Function used to determine the order of the elements. It is expected to return + * a negative value if first argument is less than second argument, zero if they're equal and a positive + * value otherwise. If omitted, the elements are sorted in ascending order. + * ```ts + * [11,2,22,1].sort((a, b) => a - b) + * ``` + */ + toSorted(compareFn?: (a: number, b: number) => number): Float32Array; + + with(index: number, value: number): Float32Array; } interface Float64Array { @@ -280,6 +475,22 @@ interface Float64Array { * predicate. If it is not provided, undefined is used instead. */ findIndexLast(predicate: (value: number, index: number, obj: Float64Array) => boolean, thisArg?: any): number; + + /** Copies and reverses the elements in an array.*/ + toReversed(): Float64Array; + + /** + * Copies and sorts an array. + * @param compareFn Function used to determine the order of the elements. It is expected to return + * a negative value if first argument is less than second argument, zero if they're equal and a positive + * value otherwise. If omitted, the elements are sorted in ascending order. + * ```ts + * [11,2,22,1].sort((a, b) => a - b) + * ``` + */ + toSorted(compareFn?: (a: number, b: number) => number): Float64Array; + + with(index: number, value: number): Float64Array; } interface BigInt64Array { @@ -304,6 +515,23 @@ interface BigInt64Array { * predicate. If it is not provided, undefined is used instead. */ findIndexLast(predicate: (value: bigint, index: number, obj: BigInt64Array) => boolean, thisArg?: any): bigint; + + + /** Copies and reverses the elements in an array.*/ + toReversed(): BigInt64Array; + + /** + * Copies and sorts an array. + * @param compareFn Function used to determine the order of the elements. It is expected to return + * a negative value if first argument is less than second argument, zero if they're equal and a positive + * value otherwise. If omitted, the elements are sorted in ascending order. + * ```ts + * [11,2,22,1].sort((a, b) => a - b) + * ``` + */ + toSorted(compareFn?: (a: number, b: number) => number): BigInt64Array; + + with(index: number, value: number): BigInt64Array; } interface BigUint64Array { @@ -328,4 +556,21 @@ interface BigUint64Array { * predicate. If it is not provided, undefined is used instead. */ findIndexLast(predicate: (value: bigint, index: number, obj: BigUint64Array) => boolean, thisArg?: any): bigint; + + + /** Copies and reverses the elements in an array.*/ + toReversed(): BigUint64Array; + + /** + * Copies and sorts an array. + * @param compareFn Function used to determine the order of the elements. It is expected to return + * a negative value if first argument is less than second argument, zero if they're equal and a positive + * value otherwise. If omitted, the elements are sorted in ascending order. + * ```ts + * [11,2,22,1].sort((a, b) => a - b) + * ``` + */ + toSorted(compareFn?: (a: number, b: number) => number): BigUint64Array; + + with(index: number, value: number): BigUint64Array; } From 47cba8ffa29f91db2dc073476717ab1876e0d26b Mon Sep 17 00:00:00 2001 From: crowlkats Date: Mon, 31 Oct 2022 20:31:58 +0100 Subject: [PATCH 2/6] feat(cli/dts): add typings for Change Array by copy proposal --- cli/dts/lib.esnext.array.d.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/cli/dts/lib.esnext.array.d.ts b/cli/dts/lib.esnext.array.d.ts index bb53d95efd12a1..46cfba9143539a 100644 --- a/cli/dts/lib.esnext.array.d.ts +++ b/cli/dts/lib.esnext.array.d.ts @@ -435,7 +435,6 @@ interface Float32Array { */ findIndexLast(predicate: (value: number, index: number, obj: Float32Array) => boolean, thisArg?: any): number; - /** Copies and reverses the elements in an array.*/ toReversed(): Float32Array; @@ -516,7 +515,6 @@ interface BigInt64Array { */ findIndexLast(predicate: (value: bigint, index: number, obj: BigInt64Array) => boolean, thisArg?: any): bigint; - /** Copies and reverses the elements in an array.*/ toReversed(): BigInt64Array; @@ -557,7 +555,6 @@ interface BigUint64Array { */ findIndexLast(predicate: (value: bigint, index: number, obj: BigUint64Array) => boolean, thisArg?: any): bigint; - /** Copies and reverses the elements in an array.*/ toReversed(): BigUint64Array; From 5131b6e54872a4aca93e227da912844075c86852 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Mon, 31 Oct 2022 20:54:11 +0100 Subject: [PATCH 3/6] fix bigint --- cli/dts/lib.esnext.array.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/dts/lib.esnext.array.d.ts b/cli/dts/lib.esnext.array.d.ts index 46cfba9143539a..ee3ecc2715d166 100644 --- a/cli/dts/lib.esnext.array.d.ts +++ b/cli/dts/lib.esnext.array.d.ts @@ -527,7 +527,7 @@ interface BigInt64Array { * [11,2,22,1].sort((a, b) => a - b) * ``` */ - toSorted(compareFn?: (a: number, b: number) => number): BigInt64Array; + toSorted(compareFn?: (a: bigint, b: bigint) => number | bigint): BigInt64Array; with(index: number, value: number): BigInt64Array; } @@ -567,7 +567,7 @@ interface BigUint64Array { * [11,2,22,1].sort((a, b) => a - b) * ``` */ - toSorted(compareFn?: (a: number, b: number) => number): BigUint64Array; + toSorted(compareFn?: (a: bigint, b: bigint) => number | bigint): BigUint64Array; with(index: number, value: number): BigUint64Array; } From c2bab00bce5cad804681dd1c3bd7650d63015f3f Mon Sep 17 00:00:00 2001 From: crowlkats Date: Mon, 31 Oct 2022 21:22:35 +0100 Subject: [PATCH 4/6] relax typings for tospliced --- cli/dts/lib.esnext.array.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/dts/lib.esnext.array.d.ts b/cli/dts/lib.esnext.array.d.ts index ee3ecc2715d166..011cbd627c0ba4 100644 --- a/cli/dts/lib.esnext.array.d.ts +++ b/cli/dts/lib.esnext.array.d.ts @@ -59,7 +59,7 @@ interface Array { * @param deleteCount The number of elements to remove. * @returns An array containing the elements that were deleted. */ - toSpliced(start: number, deleteCount?: number): T[]; + toSpliced(start: number, deleteCount?: number): any[]; /** * Copies and removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. * @param start The zero-based location in the array from which to start removing elements. @@ -67,7 +67,7 @@ interface Array { * @param items Elements to insert into the array in place of the deleted elements. * @returns An array containing the elements that were deleted. */ - toSpliced(start: number, deleteCount: number, ...items: T[]): T[]; + toSpliced(start: number, deleteCount: number, ...items: any[]): any[]; with(index: number, value: any): any[]; } @@ -116,7 +116,7 @@ interface ReadonlyArray { * @param deleteCount The number of elements to remove. * @returns An array containing the elements that were deleted. */ - toSpliced(start: number, deleteCount?: number): T[]; + toSpliced(start: number, deleteCount?: number): any[]; /** * Copies and removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. * @param start The zero-based location in the array from which to start removing elements. @@ -124,7 +124,7 @@ interface ReadonlyArray { * @param items Elements to insert into the array in place of the deleted elements. * @returns An array containing the elements that were deleted. */ - toSpliced(start: number, deleteCount: number, ...items: T[]): T[]; + toSpliced(start: number, deleteCount: number, ...items: any[]): any[]; with(index: number, value: any): any[]; } From 63e9f863fc1f44989d089486043d1f8c3d2440b2 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Mon, 31 Oct 2022 22:01:38 +0100 Subject: [PATCH 5/6] stricten typings --- cli/dts/lib.esnext.array.d.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cli/dts/lib.esnext.array.d.ts b/cli/dts/lib.esnext.array.d.ts index 011cbd627c0ba4..5ce2ce65a18982 100644 --- a/cli/dts/lib.esnext.array.d.ts +++ b/cli/dts/lib.esnext.array.d.ts @@ -59,7 +59,7 @@ interface Array { * @param deleteCount The number of elements to remove. * @returns An array containing the elements that were deleted. */ - toSpliced(start: number, deleteCount?: number): any[]; + toSpliced(start: number, deleteCount?: number): T[]; /** * Copies and removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. * @param start The zero-based location in the array from which to start removing elements. @@ -67,9 +67,9 @@ interface Array { * @param items Elements to insert into the array in place of the deleted elements. * @returns An array containing the elements that were deleted. */ - toSpliced(start: number, deleteCount: number, ...items: any[]): any[]; + toSpliced(start: number, deleteCount: number, ...items: F[]): (F | T)[]; - with(index: number, value: any): any[]; + with(index: number, value: F): (F | T)[]; } interface ReadonlyArray { @@ -124,9 +124,9 @@ interface ReadonlyArray { * @param items Elements to insert into the array in place of the deleted elements. * @returns An array containing the elements that were deleted. */ - toSpliced(start: number, deleteCount: number, ...items: any[]): any[]; + toSpliced(start: number, deleteCount: number, ...items: F[]): (F | T)[]; - with(index: number, value: any): any[]; + with(index: number, value: F): (F | T)[]; } interface Int8Array { From d3c2b9c04a5290e4df80fe9acc6c24a1ea2d500a Mon Sep 17 00:00:00 2001 From: crowlkats Date: Wed, 2 Nov 2022 16:32:41 +0100 Subject: [PATCH 6/6] add docs --- cli/dts/lib.esnext.array.d.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cli/dts/lib.esnext.array.d.ts b/cli/dts/lib.esnext.array.d.ts index 5ce2ce65a18982..527982ef700244 100644 --- a/cli/dts/lib.esnext.array.d.ts +++ b/cli/dts/lib.esnext.array.d.ts @@ -69,6 +69,11 @@ interface Array { */ toSpliced(start: number, deleteCount: number, ...items: F[]): (F | T)[]; + /** + * Copies and replaces the element at the given index with the provided value. + * @param index The zero-based location in the array for which to replace an element. + * @param value Element to insert into the array in place of the replaced element. + */ with(index: number, value: F): (F | T)[]; } @@ -116,7 +121,7 @@ interface ReadonlyArray { * @param deleteCount The number of elements to remove. * @returns An array containing the elements that were deleted. */ - toSpliced(start: number, deleteCount?: number): any[]; + toSpliced(start: number, deleteCount?: number): T[]; /** * Copies and removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. * @param start The zero-based location in the array from which to start removing elements. @@ -126,6 +131,11 @@ interface ReadonlyArray { */ toSpliced(start: number, deleteCount: number, ...items: F[]): (F | T)[]; + /** + * Copies and replaces the element at the given index with the provided value. + * @param index The zero-based location in the array for which to replace an element. + * @param value Element to insert into the array in place of the replaced element. + */ with(index: number, value: F): (F | T)[]; }