Skip to content

Commit fe2cb8e

Browse files
authored
Add missing index parameter to the Array.fromAsync's mapFn (#59837)
1 parent a709f98 commit fe2cb8e

File tree

5 files changed

+103
-53
lines changed

5 files changed

+103
-53
lines changed

src/lib/esnext.array.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ interface ArrayConstructor {
1313
* Each return value is awaited before being added to result array.
1414
* @param thisArg Value of 'this' used when executing mapfn.
1515
*/
16-
fromAsync<T, U>(iterableOrArrayLike: AsyncIterable<T> | Iterable<T> | ArrayLike<T>, mapFn: (value: Awaited<T>) => U, thisArg?: any): Promise<Awaited<U>[]>;
16+
fromAsync<T, U>(iterableOrArrayLike: AsyncIterable<T> | Iterable<T> | ArrayLike<T>, mapFn: (value: Awaited<T>, index: number) => U, thisArg?: any): Promise<Awaited<U>[]>;
1717
}

tests/baselines/reference/arrayFromAsync.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function * genPromises (n) {
1212
yield Promise.resolve(i * 2);
1313
}
1414
}
15-
15+
1616
const arrLike = {
1717
0: Promise.resolve(0),
1818
1: Promise.resolve(2),
@@ -42,7 +42,10 @@ const mapArr3 = await Array.fromAsync([0,2,4,6], v => v ** 2);
4242
const err = new Error;
4343
const badIterable = { [Symbol.iterator] () { throw err; } };
4444
// This returns a promise that will reject with `err`.
45-
const badArray = await Array.fromAsync(badIterable);
45+
const badArray = await Array.fromAsync(badIterable);
46+
47+
const withIndexResult = await Array.fromAsync(["a", "b"], (str, index) => ({ index, str }));
48+
4649

4750
//// [arrayFromAsync.js]
4851
async function* asyncGen(n) {
@@ -79,4 +82,5 @@ const err = new Error;
7982
const badIterable = { [Symbol.iterator]() { throw err; } };
8083
// This returns a promise that will reject with `err`.
8184
const badArray = await Array.fromAsync(badIterable);
85+
const withIndexResult = await Array.fromAsync(["a", "b"], (str, index) => ({ index, str }));
8286
export {};

tests/baselines/reference/arrayFromAsync.symbols

+11-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function * genPromises (n) {
3333
>i : Symbol(i, Decl(arrayFromAsync.ts, 7, 12))
3434
}
3535
}
36-
36+
3737
const arrLike = {
3838
>arrLike : Symbol(arrLike, Decl(arrayFromAsync.ts, 12, 5))
3939

@@ -185,3 +185,13 @@ const badArray = await Array.fromAsync(badIterable);
185185
>fromAsync : Symbol(ArrayConstructor.fromAsync, Decl(lib.esnext.array.d.ts, --, --), Decl(lib.esnext.array.d.ts, --, --))
186186
>badIterable : Symbol(badIterable, Decl(arrayFromAsync.ts, 39, 5))
187187

188+
const withIndexResult = await Array.fromAsync(["a", "b"], (str, index) => ({ index, str }));
189+
>withIndexResult : Symbol(withIndexResult, Decl(arrayFromAsync.ts, 43, 5))
190+
>Array.fromAsync : Symbol(ArrayConstructor.fromAsync, Decl(lib.esnext.array.d.ts, --, --), Decl(lib.esnext.array.d.ts, --, --))
191+
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more)
192+
>fromAsync : Symbol(ArrayConstructor.fromAsync, Decl(lib.esnext.array.d.ts, --, --), Decl(lib.esnext.array.d.ts, --, --))
193+
>str : Symbol(str, Decl(arrayFromAsync.ts, 43, 59))
194+
>index : Symbol(index, Decl(arrayFromAsync.ts, 43, 63))
195+
>index : Symbol(index, Decl(arrayFromAsync.ts, 43, 76))
196+
>str : Symbol(str, Decl(arrayFromAsync.ts, 43, 83))
197+

0 commit comments

Comments
 (0)