Is there a way in TypeScript for a class to reference its constructor in a manner that functions correctly when it is extended by another class?
abstract class Base<T> {
constructor(readonly value: T) {}
abstract getName(): string;
clone() {
const Cls = this.constructor;
return new Cls(this.value);
}
}
In the above code snippet, Cls
is assigned the type of Function
, resulting in a compiler error stating: "Cannot use 'new' with an expression whose type lacks a call or construct signature."