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

make Array explicitly extend ReadonlyArray and use this type in the callbacks #46781

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
30 changes: 4 additions & 26 deletions src/lib/es2015.core.d.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,4 @@
interface Array<T> {
/**
* Returns the value of the first element in the array where predicate is true, and undefined
* otherwise.
* @param predicate find calls predicate once for each element of the array, in ascending
* order, until it finds one where predicate returns true. If such an element is found, find
* immediately returns that element value. Otherwise, find returns undefined.
* @param thisArg If provided, it will be used as the this value for each invocation of
* predicate. If it is not provided, undefined is used instead.
*/
find<S extends T>(predicate: (this: void, value: T, index: number, obj: T[]) => value is S, thisArg?: any): S | undefined;
find(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): T | undefined;

/**
* Returns the index of the first element in the array where predicate is true, and -1
* otherwise.
* @param predicate find calls predicate once for each element of the array, in ascending
* order, until it finds one where predicate returns true. If such an element is found,
* findIndex immediately returns that element index. Otherwise, findIndex returns -1.
* @param thisArg If provided, it will be used as the this value for each invocation of
* predicate. If it is not provided, undefined is used instead.
*/
findIndex(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): number;
interface Array<T> extends ReadonlyArray<T> {

/**
* Changes all array elements from `start` to `end` index to a static `value` and returns the modified array
@@ -329,8 +307,8 @@ interface ReadonlyArray<T> {
* @param thisArg If provided, it will be used as the this value for each invocation of
* predicate. If it is not provided, undefined is used instead.
*/
find<S extends T>(predicate: (this: void, value: T, index: number, obj: readonly T[]) => value is S, thisArg?: any): S | undefined;
find(predicate: (value: T, index: number, obj: readonly T[]) => unknown, thisArg?: any): T | undefined;
find<S extends T>(predicate: (this: void, value: T, index: number, obj: this) => value is S, thisArg?: any): S | undefined;
find(predicate: (value: T, index: number, obj: this) => unknown, thisArg?: any): T | undefined;

/**
* Returns the index of the first element in the array where predicate is true, and -1
@@ -341,7 +319,7 @@ interface ReadonlyArray<T> {
* @param thisArg If provided, it will be used as the this value for each invocation of
* predicate. If it is not provided, undefined is used instead.
*/
findIndex(predicate: (value: T, index: number, obj: readonly T[]) => unknown, thisArg?: any): number;
findIndex(predicate: (value: T, index: number, obj: this) => unknown, thisArg?: any): number;
}

interface RegExp {
20 changes: 0 additions & 20 deletions src/lib/es2015.iterable.d.ts
Original file line number Diff line number Diff line change
@@ -35,26 +35,6 @@ interface IterableIterator<T> extends Iterator<T> {
[Symbol.iterator](): IterableIterator<T>;
}

interface Array<T> {
/** Iterator */
[Symbol.iterator](): IterableIterator<T>;

/**
* Returns an iterable of key, value pairs for every entry in the array
*/
entries(): IterableIterator<[number, T]>;

/**
* Returns an iterable of keys in the array
*/
keys(): IterableIterator<number>;

/**
* Returns an iterable of values in the array
*/
values(): IterableIterator<T>;
}

interface ArrayConstructor {
/**
* Creates an array from an iterable object.
2 changes: 1 addition & 1 deletion src/lib/es2015.symbol.wellknown.d.ts
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@ interface Symbol {
readonly [Symbol.toStringTag]: string;
}

interface Array<T> {
interface Array<T> extends ReadonlyArray<T> {
/**
* Returns an object whose properties have the value 'true'
* when they will be absent when used in a 'with' statement.
9 changes: 0 additions & 9 deletions src/lib/es2016.array.include.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
interface Array<T> {
/**
* Determines whether an array includes a certain element, returning true or false as appropriate.
* @param searchElement The element to search for.
* @param fromIndex The position in this array at which to begin searching for searchElement.
*/
includes(searchElement: T, fromIndex?: number): boolean;
}

interface ReadonlyArray<T> {
/**
* Determines whether an array includes a certain element, returning true or false as appropriate.
29 changes: 0 additions & 29 deletions src/lib/es2019.array.d.ts
Original file line number Diff line number Diff line change
@@ -23,35 +23,6 @@ interface ReadonlyArray<T> {
): 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<A, D extends number = 1>(
this: A,
depth?: D
): FlatArray<A, D>[]
}

interface Array<T> {

/**
* Calls a defined callback function on each element of an array. Then, flattens the result into
* a new array.
* This is identical to a map followed by flat with depth 1.
*
* @param callback A function that accepts up to three arguments. The flatMap method calls the
* callback function one time for each element in the array.
* @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.
8 changes: 0 additions & 8 deletions src/lib/es2022.array.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
interface Array<T> {
/**
* Returns the item located at the specified index.
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
*/
at(index: number): T | undefined;
}

interface ReadonlyArray<T> {
/**
* Returns the item located at the specified index.
Loading
Oops, something went wrong.