From 7128537650699f2c464d60d33c1d220effd55ba7 Mon Sep 17 00:00:00 2001 From: James Prevett Date: Tue, 26 Nov 2024 10:39:44 -0600 Subject: [PATCH] Add `Promise.withResolvers` polyfill --- src/polyfills/Promise.withResolvers.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/polyfills/Promise.withResolvers.ts diff --git a/src/polyfills/Promise.withResolvers.ts b/src/polyfills/Promise.withResolvers.ts new file mode 100644 index 0000000..37e186c --- /dev/null +++ b/src/polyfills/Promise.withResolvers.ts @@ -0,0 +1,18 @@ +/// + +// eslint-disable-next-line @typescript-eslint/unbound-method +Promise.withResolvers ??= function (): PromiseWithResolvers { + let resolve: (value: T | PromiseLike) => void, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + reject: (reason?: any) => void; + const promise = new Promise((res, rej) => { + resolve = res; + reject = rej; + }); + return { promise, resolve, reject }; +}; + +// @ts-expect-error 2540 +Symbol['dispose'] ??= Symbol('Symbol.dispose'); +// @ts-expect-error 2540 +Symbol['asyncDispose'] ??= Symbol('Symbol.asyncDispose');