The class name reflects the specific type of an instance within a class (such as the output type of an expression like new Model()
).
However, the class itself also possesses its own type. This type includes the constructor signature and the static members of the class. To access this type, you must use typeof ClassName
.
A function that returns typeof Model
indicates that it will yield a new class (not an instance) that is derived from Model
.
You could then proceed to create an instance of the class:
let myModelClass = define(...);
let myModelInstance = new myModelClass()
Keep in mind, if you ever require the instance type of a class defined in this manner, you will need to utilize
InstanceType<typeof myModelClass>
. This is because only a class declaration introduces a type with the same name; a variable will not establish such a type. Creating a type alias might streamline things and lead to more anticipated outcomes:
let myModel = define(...);
type myModel = InstanceType<typeof myModel>
let myModelInstance: myModel = new myModel()