Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS: Cannot extend Promise object: No base constructor has the specified number of type arguments

I am attempting to extend the Promise object with the following code:

class MyPromise extends Promise {
    constructor(executor) {
        super((resolve, reject) => {
            return executor(resolve, reject);
        });
    }
}

However, I am getting the following error: enter image description here

What does this error mean? How can I successfully extend Promise?

like image 672
aBlaze Avatar asked Oct 23 '25 06:10

aBlaze


1 Answers

Try this...

class MyPromise<T> extends Promise<T> {
    constructor(executor: (resolve: any, reject: any) => MyPromise<T>) {
        super((resolve, reject) => {
            return executor(resolve, reject);
        });
    }
}
like image 190
Will Walsh Avatar answered Oct 24 '25 21:10

Will Walsh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!