Within my code, there is an abstract class that uses new this()
. Surprisingly, this action is not creating an instance of the abstract class itself but is generating an instance of the class that inherits from it.
Even though this behavior is acceptable in JavaScript when compiled, TypeScript is not pleased with it.
The error thrown is: "Cannot create an instance of an abstract class."
abstract class Model {
static find<T extends Model>(someVar) {
let inst = new this() as T
// Additional operations applied to the instance
return inst
}
}
class A extends Model { }
A.find()