Let's say I have
abstract class Foo {
}
class Bar1 extends Foo {
constructor(someVar) { ... }
}
class Bar2 extends Foo {
constructor(someVar) { ... }
}
I'd like to be able to create a static method that creates an instance of the final class (all constructors would have the same signature). So I want something like:
abstract class Foo {
public static someAction(someVar) {
const self = new this(someVar);
}
}
But this cannot be done because Foo is abstract. Is this at all possible?
UPDATE
What if these classes have their own templates?
abstract class Foo<M> {
}
class Bar1 extends Foo<SomeModel> {...}
Now I want the someAction to know of the type SomeModel. I tried
public static someAction<A, T extends Foo<A>>(this: new (someVar: any) => T, someVar: any): T {
const self = new this(someVar);
return self;
}
But unless I specifically do Bar1.someAction<SomeModel>("blah") the returned result is not available of the type of the data, i.e. Bar1.someAction("blah") doesn't know the data type