Is there a way in TypeScript to create new instances from a static method in a generic way?
I want to do something like:
class Base {
static getInstance() {
return new self(); // i need this line :)
}
}
class Test extends Base {
}
class NextTest extends Base {
}
var test = Test.getInstance();
assert(test instanceof Test).toBe(true);
var nextTest = NextTest.getInstance();
assert(nextTest instanceof NextTest).toBe(true);
It would be really helpful if someone did something like this before and could help me. Maybe there is a JavaScript way?
Thanks in advance.