Here is a sample class (supposed to be immutable):
class A {
normalMethod1(): A{
const instance = this.staticMethod1();
return instance;
}
static staticMethod1: A(){
return new this();
}
}
The code above works fine, but how can I replace A.staticMethod
with the current class name? Perhaps something like this.staticMethod
(which triggers ts2576 error).
This applies for return types as well. How do we update them dynamically based on the current class?
The main reason for this practice is ensuring that renaming the class in future only requires modification in one location instead of multiple places.