diff --git a/lib/defer.ts b/lib/defer.ts index e259303..213b213 100644 --- a/lib/defer.ts +++ b/lib/defer.ts @@ -1,16 +1,18 @@ -export default function defer(): Promise & { resolve: (v: any) => void; reject: (err: Error) => void } { +class Defer extends Promise { + resolve: (value: unknown) => void; + reject: (reason?: any) => void; +} + +export default function defer(): Defer { let res; let rej; - const promise = new Promise((resolve, reject) => { + const promise = new Defer((resolve, reject) => { res = resolve; rej = reject; }); - // @ts-ignore promise.resolve = res; - // @ts-ignore promise.reject = rej; - // @ts-ignore return promise; }