Skip to content

Commit

Permalink
Fix some typing
Browse files Browse the repository at this point in the history
  • Loading branch information
OlliV committed Oct 26, 2023
1 parent 708e9aa commit 08ea7c0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/defer.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
export default function defer(): Promise<any> & { resolve: (v: any) => void; reject: (err: Error) => void } {
class Defer<T> extends Promise<T> {
resolve: (value: unknown) => void;
reject: (reason?: any) => void;
}

export default function defer<T>(): Defer<T> {
let res;
let rej;
const promise = new Promise((resolve, reject) => {
const promise = new Defer<T>((resolve, reject) => {
res = resolve;
rej = reject;
});

// @ts-ignore
promise.resolve = res;
// @ts-ignore
promise.reject = rej;

// @ts-ignore
return promise;
}

0 comments on commit 08ea7c0

Please sign in to comment.