mirror of
https://github.com/documenso/documenso.git
synced 2026-07-24 00:43:40 +10:00
31 lines
836 B
TypeScript
31 lines
836 B
TypeScript
/**
|
|
* Polyfill for Promise.withResolvers (ES2024)
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers
|
|
*/
|
|
|
|
type PromiseWithResolvers<T> = {
|
|
promise: Promise<T>;
|
|
resolve: (value: T | PromiseLike<T>) => void;
|
|
reject: (reason?: unknown) => void;
|
|
};
|
|
|
|
// We're patching here
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
const GlobalPromise = globalThis.Promise as any;
|
|
|
|
if (typeof GlobalPromise.withResolvers !== 'function') {
|
|
GlobalPromise.withResolvers = <T>(): PromiseWithResolvers<T> => {
|
|
let resolve!: (value: T | PromiseLike<T>) => void;
|
|
let reject!: (reason?: unknown) => void;
|
|
|
|
const promise = new Promise<T>((res, rej) => {
|
|
resolve = res;
|
|
reject = rej;
|
|
});
|
|
|
|
return { promise, resolve, reject };
|
|
};
|
|
}
|
|
|
|
export {};
|