Skip to content

Commit f009cf6

Browse files
committed
make Array explicitly extend ReadonlyArray
1 parent 7b86a65 commit f009cf6

7 files changed

+3
-221
lines changed

src/lib/es2015.core.d.ts

+1-23
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,4 @@
1-
interface Array<T> {
2-
/**
3-
* Returns the value of the first element in the array where predicate is true, and undefined
4-
* otherwise.
5-
* @param predicate find calls predicate once for each element of the array, in ascending
6-
* order, until it finds one where predicate returns true. If such an element is found, find
7-
* immediately returns that element value. Otherwise, find returns undefined.
8-
* @param thisArg If provided, it will be used as the this value for each invocation of
9-
* predicate. If it is not provided, undefined is used instead.
10-
*/
11-
find<S extends T>(predicate: (this: void, value: T, index: number, obj: T[]) => value is S, thisArg?: any): S | undefined;
12-
find(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): T | undefined;
13-
14-
/**
15-
* Returns the index of the first element in the array where predicate is true, and -1
16-
* otherwise.
17-
* @param predicate find calls predicate once for each element of the array, in ascending
18-
* order, until it finds one where predicate returns true. If such an element is found,
19-
* findIndex immediately returns that element index. Otherwise, findIndex returns -1.
20-
* @param thisArg If provided, it will be used as the this value for each invocation of
21-
* predicate. If it is not provided, undefined is used instead.
22-
*/
23-
findIndex(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): number;
1+
interface Array<T> extends ReadonlyArray<T> {
242

253
/**
264
* Changes all array elements from `start` to `end` index to a static `value` and returns the modified array

src/lib/es2015.iterable.d.ts

-20
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,6 @@ interface IterableIterator<T> extends Iterator<T> {
3535
[Symbol.iterator](): IterableIterator<T>;
3636
}
3737

38-
interface Array<T> {
39-
/** Iterator */
40-
[Symbol.iterator](): IterableIterator<T>;
41-
42-
/**
43-
* Returns an iterable of key, value pairs for every entry in the array
44-
*/
45-
entries(): IterableIterator<[number, T]>;
46-
47-
/**
48-
* Returns an iterable of keys in the array
49-
*/
50-
keys(): IterableIterator<number>;
51-
52-
/**
53-
* Returns an iterable of values in the array
54-
*/
55-
values(): IterableIterator<T>;
56-
}
57-
5838
interface ArrayConstructor {
5939
/**
6040
* Creates an array from an iterable object.

src/lib/es2015.symbol.wellknown.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ interface Symbol {
7171
readonly [Symbol.toStringTag]: string;
7272
}
7373

74-
interface Array<T> {
74+
interface Array<T> extends ReadonlyArray<T> {
7575
/**
7676
* Returns an object whose properties have the value 'true'
7777
* when they will be absent when used in a 'with' statement.

src/lib/es2016.array.include.d.ts

-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
interface Array<T> {
2-
/**
3-
* Determines whether an array includes a certain element, returning true or false as appropriate.
4-
* @param searchElement The element to search for.
5-
* @param fromIndex The position in this array at which to begin searching for searchElement.
6-
*/
7-
includes(searchElement: T, fromIndex?: number): boolean;
8-
}
9-
101
interface ReadonlyArray<T> {
112
/**
123
* Determines whether an array includes a certain element, returning true or false as appropriate.

src/lib/es2019.array.d.ts

-29
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,6 @@ interface ReadonlyArray<T> {
2323
): U[]
2424

2525

26-
/**
27-
* Returns a new array with all sub-array elements concatenated into it recursively up to the
28-
* specified depth.
29-
*
30-
* @param depth The maximum recursion depth
31-
*/
32-
flat<A, D extends number = 1>(
33-
this: A,
34-
depth?: D
35-
): FlatArray<A, D>[]
36-
}
37-
38-
interface Array<T> {
39-
40-
/**
41-
* Calls a defined callback function on each element of an array. Then, flattens the result into
42-
* a new array.
43-
* This is identical to a map followed by flat with depth 1.
44-
*
45-
* @param callback A function that accepts up to three arguments. The flatMap method calls the
46-
* callback function one time for each element in the array.
47-
* @param thisArg An object to which the this keyword can refer in the callback function. If
48-
* thisArg is omitted, undefined is used as the this value.
49-
*/
50-
flatMap<U, This = undefined> (
51-
callback: (this: This, value: T, index: number, array: T[]) => U | ReadonlyArray<U>,
52-
thisArg?: This
53-
): U[]
54-
5526
/**
5627
* Returns a new array with all sub-array elements concatenated into it recursively up to the
5728
* specified depth.

src/lib/es2022.array.d.ts

-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
interface Array<T> {
2-
/**
3-
* Returns the item located at the specified index.
4-
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
5-
*/
6-
at(index: number): T | undefined;
7-
}
8-
91
interface ReadonlyArray<T> {
102
/**
113
* Returns the item located at the specified index.

src/lib/es5.d.ts

+1-131
Original file line numberDiff line numberDiff line change
@@ -1246,19 +1246,7 @@ interface ConcatArray<T> {
12461246
slice(start?: number, end?: number): T[];
12471247
}
12481248

1249-
interface Array<T> {
1250-
/**
1251-
* Gets or sets the length of the array. This is a number one higher than the highest index in the array.
1252-
*/
1253-
length: number;
1254-
/**
1255-
* Returns a string representation of an array.
1256-
*/
1257-
toString(): string;
1258-
/**
1259-
* Returns a string representation of an array. The elements are converted to string using their toLocaleString methods.
1260-
*/
1261-
toLocaleString(): string;
1249+
interface Array<T> extends ReadonlyArray<T> {
12621250
/**
12631251
* Removes the last element from an array and returns it.
12641252
* If the array is empty, undefined is returned and the array is not modified.
@@ -1269,23 +1257,6 @@ interface Array<T> {
12691257
* @param items New elements to add to the array.
12701258
*/
12711259
push(...items: T[]): number;
1272-
/**
1273-
* Combines two or more arrays.
1274-
* This method returns a new array without modifying any existing arrays.
1275-
* @param items Additional arrays and/or items to add to the end of the array.
1276-
*/
1277-
concat(...items: ConcatArray<T>[]): T[];
1278-
/**
1279-
* Combines two or more arrays.
1280-
* This method returns a new array without modifying any existing arrays.
1281-
* @param items Additional arrays and/or items to add to the end of the array.
1282-
*/
1283-
concat(...items: (T | ConcatArray<T>)[]): T[];
1284-
/**
1285-
* Adds all the elements of an array into a string, separated by the specified separator string.
1286-
* @param separator A string used to separate one element of the array from the next in the resulting string. If omitted, the array elements are separated with a comma.
1287-
*/
1288-
join(separator?: string): string;
12891260
/**
12901261
* Reverses the elements in an array in place.
12911262
* This method mutates the array and returns a reference to the same array.
@@ -1296,16 +1267,6 @@ interface Array<T> {
12961267
* If the array is empty, undefined is returned and the array is not modified.
12971268
*/
12981269
shift(): T | undefined;
1299-
/**
1300-
* Returns a copy of a section of an array.
1301-
* For both start and end, a negative index can be used to indicate an offset from the end of the array.
1302-
* For example, -2 refers to the second to last element of the array.
1303-
* @param start The beginning index of the specified portion of the array.
1304-
* If start is undefined, then the slice begins at index 0.
1305-
* @param end The end index of the specified portion of the array. This is exclusive of the element at the index 'end'.
1306-
* If end is undefined, then the slice extends to the end of the array.
1307-
*/
1308-
slice(start?: number, end?: number): T[];
13091270
/**
13101271
* Sorts an array in place.
13111272
* This method mutates the array and returns a reference to the same array.
@@ -1337,97 +1298,6 @@ interface Array<T> {
13371298
* @param items Elements to insert at the start of the array.
13381299
*/
13391300
unshift(...items: T[]): number;
1340-
/**
1341-
* Returns the index of the first occurrence of a value in an array, or -1 if it is not present.
1342-
* @param searchElement The value to locate in the array.
1343-
* @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
1344-
*/
1345-
indexOf(searchElement: T, fromIndex?: number): number;
1346-
/**
1347-
* Returns the index of the last occurrence of a specified value in an array, or -1 if it is not present.
1348-
* @param searchElement The value to locate in the array.
1349-
* @param fromIndex The array index at which to begin searching backward. If fromIndex is omitted, the search starts at the last index in the array.
1350-
*/
1351-
lastIndexOf(searchElement: T, fromIndex?: number): number;
1352-
/**
1353-
* Determines whether all the members of an array satisfy the specified test.
1354-
* @param predicate A function that accepts up to three arguments. The every method calls
1355-
* the predicate function for each element in the array until the predicate returns a value
1356-
* which is coercible to the Boolean value false, or until the end of the array.
1357-
* @param thisArg An object to which the this keyword can refer in the predicate function.
1358-
* If thisArg is omitted, undefined is used as the this value.
1359-
*/
1360-
every<S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any): this is S[];
1361-
/**
1362-
* Determines whether all the members of an array satisfy the specified test.
1363-
* @param predicate A function that accepts up to three arguments. The every method calls
1364-
* the predicate function for each element in the array until the predicate returns a value
1365-
* which is coercible to the Boolean value false, or until the end of the array.
1366-
* @param thisArg An object to which the this keyword can refer in the predicate function.
1367-
* If thisArg is omitted, undefined is used as the this value.
1368-
*/
1369-
every(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean;
1370-
/**
1371-
* Determines whether the specified callback function returns true for any element of an array.
1372-
* @param predicate A function that accepts up to three arguments. The some method calls
1373-
* the predicate function for each element in the array until the predicate returns a value
1374-
* which is coercible to the Boolean value true, or until the end of the array.
1375-
* @param thisArg An object to which the this keyword can refer in the predicate function.
1376-
* If thisArg is omitted, undefined is used as the this value.
1377-
*/
1378-
some(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean;
1379-
/**
1380-
* Performs the specified action for each element in an array.
1381-
* @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
1382-
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
1383-
*/
1384-
forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void;
1385-
/**
1386-
* Calls a defined callback function on each element of an array, and returns an array that contains the results.
1387-
* @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
1388-
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
1389-
*/
1390-
map<U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[];
1391-
/**
1392-
* Returns the elements of an array that meet the condition specified in a callback function.
1393-
* @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
1394-
* @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
1395-
*/
1396-
filter<S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[];
1397-
/**
1398-
* Returns the elements of an array that meet the condition specified in a callback function.
1399-
* @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
1400-
* @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
1401-
*/
1402-
filter(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): T[];
1403-
/**
1404-
* Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
1405-
* @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
1406-
* @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
1407-
*/
1408-
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T;
1409-
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T;
1410-
/**
1411-
* Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
1412-
* @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
1413-
* @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
1414-
*/
1415-
reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U;
1416-
/**
1417-
* Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
1418-
* @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
1419-
* @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
1420-
*/
1421-
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T;
1422-
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T;
1423-
/**
1424-
* Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
1425-
* @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
1426-
* @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
1427-
*/
1428-
reduceRight<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U;
1429-
1430-
[n: number]: T;
14311301
}
14321302

14331303
interface ArrayConstructor {

0 commit comments

Comments
 (0)