My current challenge involves adding a method to a prototype of PromiseLike<T>
. Adding a method to the prototype of String
was straightforward:
declare global {
interface String {
handle(): void;
}
}
String.prototype.handle = function() {
}
This code compiles without any issues.
However, when I attempt to add a similar method to PromiseLike<T>
, I encounter a compile error stating
'PromiseLike' only refers to a type, but is being used as a value here.
:
declare global {
interface PromiseLike<T> {
handle(): PromiseLike<T>;
}
}
PromiseLike.prototype.handle = function<T>(this: T):T {
return this;
}
The key issue lies in the fact that PromiseLike
is generic. How can I address this challenge effectively within TypeScript?