export default class Deferred { private promise: Promise; private _resolve: (value?: unknown) => void; private _reject: (reason?: any) => void; constructor() { this._resolve = () => {}; this._reject = () => {}; this.promise = new Promise((resolve, reject) => { this._resolve = resolve as (value?: unknown) => void; this._reject = reject; }); } public then( onfulfilled?: ((value: unknown) => TResult1 | PromiseLike) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike) | undefined | null ): Promise { return this.promise.then(onfulfilled, onrejected); } public catch( onrejected?: ((reason: any) => TResult | PromiseLike) | undefined | null ): Promise { return this.promise.catch(onrejected); } public finally(onfinally?: (() => void) | null | undefined): Promise { return this.promise.finally(onfinally); } public resolve(value?: unknown): void { this._resolve(value); } public reject(reason?: any): void { this._reject(reason); } }