Consider this scenario:
interface IAnInterface {
}
How can you refer to and point to a class type that implements the interface?
For instance, if we have a class like this:
class AClassThatImplmentsAnInterface implements IAnInterface {
}
What is the method for referencing the type that represents a class? When dealing with just classes, we could use typeof
:
typeof AClassThatImplementsAnInterface
However, when it comes to interfaces, which reference all classes implementing that interface, using typeof IAnInterface
results in an error:
'IAnInterface' only refers to a type, but is being used as a value here. (2693)
Is there a way to achieve something similar to this:
type IClassTypeMapping = {
[names in SomeLiteralStringUnion]: Class<IAnInterface>
}
The concept of Class
does not exist in TypeScript. How can you reference the equivalent of Class<IAnInterface>
? And is it feasible in TypeScript?