Q:

Create object of class within a class but not using the name

I am sorry if the heading is misleading, I can't think of a better heading.
so I have two classes like this :
class ClassA{
   getObject(){
      return new this(with some parameters)
   }
}
class ClassB extends classA{

}
let a = new ClassB();
a.getObject();

I know I can always return new ClassB() with some parameters. But ClassA is extended by some hundred classes and it will be a lot of change in every class.
So Is there a way to return object of self class in getObject method of ClassA?

A:

You can use polymorphic this to return an instance of the same type as the current class:
class ClassA {
    getObject(): this {
        // not really type safe, not really recomnded 
        return new (this as any).constructor()
    }
}
class ClassB extends ClassA {

}
let a = new ClassB();
let b = a.getObject(); // ClassB
console.log(a.getObject() instanceof ClassB); // true

You can also infer the type of this using a type parameter and use that as the return type: 
class ClassA {
    getObject<T>(this:T) : T {
        // not really type safe
        return new (this as any).constructor()
    }
}
class ClassB extends ClassA {

}
let a = new ClassB();
let b = a.getObject(); // ClassB
console.log(a.getObject() instanceof ClassB); // true

