How to add a method to a prototype of a generic class in typescript
Interfaces do not exist at runtime, they are erased during compilation, so setting the value of a function on an interface is not possible. What you are probably looking for is adding the function to Promise
. You can do this similarly:
declare global {
interface Promise<T> {
handle(): Promise<T>;
}
}
Promise.prototype.handle = function<T>(this: Promise<T>): Promise<T> {
return this;
}