Skip to content

Commit

Permalink
Add Promise.withResolvers polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed Nov 26, 2024
1 parent 589e582 commit 7128537
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/polyfills/Promise.withResolvers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/// <reference lib="esnext.promise" />

// eslint-disable-next-line @typescript-eslint/unbound-method
Promise.withResolvers ??= function <T>(): PromiseWithResolvers<T> {
let resolve: (value: T | PromiseLike<T>) => void,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
reject: (reason?: any) => void;
const promise = new Promise<T>((res, rej) => {
resolve = res;
reject = rej;
});
return { promise, resolve, reject };

Check failure on line 12 in src/polyfills/Promise.withResolvers.ts

View workflow job for this annotation

GitHub Actions / Continuous Integration

Variable 'resolve' is used before being assigned.

Check failure on line 12 in src/polyfills/Promise.withResolvers.ts

View workflow job for this annotation

GitHub Actions / Continuous Integration

Variable 'reject' is used before being assigned.
};

// @ts-expect-error 2540
Symbol['dispose'] ??= Symbol('Symbol.dispose');
// @ts-expect-error 2540
Symbol['asyncDispose'] ??= Symbol('Symbol.asyncDispose');

0 comments on commit 7128537

Please sign in to comment.