Add types for Promise.withResolvers() (#56593)

This commit is contained in:
Linus Groh
2023-11-29 16:55:55 +00:00
committed by GitHub
parent 2869579b2c
commit aef29e400e
19 changed files with 164 additions and 4 deletions

View File

@@ -221,7 +221,7 @@ const libEntries: [string, string][] = [
["esnext.disposable", "lib.esnext.disposable.d.ts"],
["esnext.bigint", "lib.es2020.bigint.d.ts"],
["esnext.string", "lib.es2022.string.d.ts"],
["esnext.promise", "lib.es2021.promise.d.ts"],
["esnext.promise", "lib.esnext.promise.d.ts"],
["esnext.weakref", "lib.es2021.weakref.d.ts"],
["esnext.decorators", "lib.esnext.decorators.d.ts"],
["decorators", "lib.decorators.d.ts"],

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

@@ -2,3 +2,4 @@
/// <reference lib="esnext.intl" />
/// <reference lib="esnext.decorators" />
/// <reference lib="esnext.disposable" />
/// <reference lib="esnext.promise" />

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

@@ -0,0 +1,17 @@
interface PromiseWithResolvers<T> {
promise: Promise<T>;
resolve: (value: T | PromiseLike<T>) => void;
reject: (reason?: any) => void;
}
interface PromiseConstructor {
/**
* Creates a new Promise and returns it in an object, along with its resolve and reject functions.
* @returns An object with the properties `promise`, `resolve`, and `reject`.
*
* ```ts
* const { promise, resolve, reject } = Promise.withResolvers<T>();
* ```
*/
withResolvers<T>(): PromiseWithResolvers<T>;
}

View File

@@ -71,6 +71,7 @@
"esnext.decorators",
"esnext.intl",
"esnext.disposable",
"esnext.promise",
"decorators",
"decorators.legacy",
// Default libraries