Is there a way to pass type information for a class, indicating to the compiler that the provided parameter is not an instance of a class but rather the definition of the class itself?
import * as Routes from '../routes';
import * as Entities from '../entities';
export class RouteManager {
public router = Router();
private connection = getConnectionManager().get();
constructor() {
this.addRoute(Routes.VideoRoute, Entities.Video);
}
addRoute(routeClass: AbstractRoute<AbstractEntity>, entity: AbstractEntity): void {
const instance = new routeClass(entity, this.connection.getRepository(entity))
this.router.get(instance.route, instance.find);
}
}
The issue arises when trying to instantiate routeClass
on the line
new routeClass(entity, this.connection.getRepository(entity))
, as the compiler interprets routeClass
as an instance of AbstractRoute<AbstractEntity>
instead of its class definition.
I attempted using
AbstractRoute<AbstractEntity>.constructor
, but it seems that Typescript is not familiar with this syntax.