If I wish to enhance the functionality of the Promise
class by customizing the then()
method to execute something before calling super.then()
:
class ExtendedPromise<T> extends Promise<T> {
then(...x: Parameters<InstanceType<typeof Promise<T>>["then"]>) {
console.log("Do something here");
return super.then(...x);
}
}
In TypeScript, there is an error stating that this override is not compatible with the same property in the parent type because unknown
cannot be assigned to type TResult1 | TResult2
. But why does this occur? I am accepting the exact parameters as the parent type and essentially returning the value from super, so all types should match, right?