Is there a method in typescript to restrict the type of an uninstantiated class?
I am looking to specify that only classes which inherit from Repository
can be accepted by the addRepository
method without actually creating an instance of the class (its constructor should only be called by the service container).
Is there a way to achieve this?
import { Repository } from '../repositories/repository';
class Factory {
addRepository(repositoryClass: Repository) /* <- what should be placed here? */ { }
}
class UserRepository extends Repository {
}
let factory = new Factory();
factory.addRepository(UserRepository); // produces error