From 08ea7c0168492e7cdb0e0e4a0395692385890c4f Mon Sep 17 00:00:00 2001 From: Olli Vanhoja Date: Thu, 26 Oct 2023 17:03:27 +0200 Subject: [PATCH] Fix some typing --- lib/defer.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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; }