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

Total
1
Shares

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?


Solution

Try this…

class MyPromise<T> extends Promise<T> {
    constructor(executor: (resolve: any, reject: any) => MyPromise<T>) {
        super((resolve, reject) => {
            return executor(resolve, reject);
        });
    }
}
Leave a Reply

Your email address will not be published. Required fields are marked *