I have an abstract class, and I would like to generate a type that matches any non-abstract subclass of that type, not its instance. Is this possible?
abstract class A {
}
function b(type: NonAbstractDescendant<typeof A>) {
}
I have an abstract class, and I would like to generate a type that matches any non-abstract subclass of that type, not its instance. Is this possible?
abstract class A {
}
function b(type: NonAbstractDescendant<typeof A>) {
}
Copyright © 2021 Jogjafile Inc.
My guess is that the function (
b) needstypeto create instances. This suggests a type like{ new() : A }(with the appropriate parameter types), or if static properties and/or methods are required{ new(): A } & typeof A. In either case, this only matches subclasses of which the constructors take compatible parameters.It is possible to avoid repeating the constructor parameters like
{ new(...args: ConstructorParameters<typeof B>): B } & typeof Bbut it is well possible that this is longer than simply repeating them.An example: