I would like to pass type information for class, with hinting the compiler that the given parameter is not an instance of a class but the class definition. How can I do that?
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);
}
}
Here the compiler complains about the new routeClass(entity, this.connection.getRepository(entity))
line because it thinks routeClass
is an instance of AbstractRoute<AbstractEntity>
and not the exported class definition for it.
I have tried usingAbstractRoute<AbstractEntity>.constructor
but Typescript doesn't seem to know this structure.