add Array.fromAsync to esnext (#57748)

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
This commit is contained in:
Isabel Duan
2024-03-19 10:43:02 -07:00
committed by GitHub
parent a9460c8c93
commit 3282ff28e6
29 changed files with 830 additions and 3 deletions

View File

@@ -233,6 +233,7 @@ const libEntries: [string, string][] = [
["esnext.weakref", "lib.es2021.weakref.d.ts"],
["esnext.decorators", "lib.esnext.decorators.d.ts"],
["esnext.object", "lib.esnext.object.d.ts"],
["esnext.array", "lib.esnext.array.d.ts"],
["esnext.regexp", "lib.esnext.regexp.d.ts"],
["decorators", "lib.decorators.d.ts"],
["decorators.legacy", "lib.decorators.legacy.d.ts"],

View File

@@ -1338,6 +1338,9 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
"from",
"of",
],
esnext: [
"fromAsync",
],
})),
ObjectConstructor: new Map(Object.entries({
es2015: [

17
src/lib/esnext.array.d.ts vendored Normal file
View File

@@ -0,0 +1,17 @@
interface ArrayConstructor {
/**
* Creates an array from an async iterator or iterable object.
* @param iterableOrArrayLike An async iterator or array-like object to convert to an array.
*/
fromAsync<T>(iterableOrArrayLike: AsyncIterable<T> | Iterable<T | PromiseLike<T>> | ArrayLike<T | PromiseLike<T>>): Promise<T[]>;
/**
* Creates an array from an async iterator or iterable object.
*
* @param iterableOrArrayLike An async iterator or array-like object to convert to an array.
* @param mapfn A mapping function to call on every element of itarableOrArrayLike.
* Each return value is awaited before being added to result array.
* @param thisArg Value of 'this' used when executing mapfn.
*/
fromAsync<T, U>(iterableOrArrayLike: AsyncIterable<T> | Iterable<T> | ArrayLike<T>, mapFn: (value: Awaited<T>) => U, thisArg?: any): Promise<Awaited<U>[]>;
}

1
src/lib/esnext.d.ts vendored
View File

@@ -5,4 +5,5 @@
/// <reference lib="esnext.promise" />
/// <reference lib="esnext.object" />
/// <reference lib="esnext.collection" />
/// <reference lib="esnext.array" />
/// <reference lib="esnext.regexp" />

View File

@@ -77,6 +77,7 @@
"esnext.promise",
"esnext.object",
"esnext.collection",
"esnext.array",
"esnext.regexp",
"decorators",
"decorators.legacy",