Created
June 24, 2024 08:22
-
-
Save johannschopplich/5be256c8d297f953fa2c3975e4d9fb5b to your computer and use it in GitHub Desktop.
Polyfill for `Promise.witResolvers()` in TypeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Promise.withResolvers ??= function <T>() { | |
let resolve: PromiseWithResolvers<T>["resolve"]; | |
let reject: PromiseWithResolvers<T>["reject"]; | |
const promise = new Promise<T>((res, rej) => { | |
resolve = res; | |
reject = rej; | |
}); | |
return { promise, resolve: resolve!, reject: reject! }; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment