For convenience, class types are the type of the class objects, and the type of the actual class (the constructor) is typeof Class
. So, in this case, you'd have to use IMakeThing<typeof Thing>
, not IMakeThing<Thing>
. You have another issue where value
will then have to be the actual class object, so you could make a ConstructedType
utility type that extracts the type constructed and uses that for the type of value
:
export class Thing{
name: string = "dunno"
}
type ConstructedType<T extends new (...args: any) => any>
= T extends new (...args: any) => infer R ? R : never;
export interface IMakeThing<T extends new (...args: any) => any>{
value: ConstructedType<T>
}
const owner = new Thing();
const test: IMakeThing<typeof Thing> = {
value: new Thing
};
Or just use the much prettier approach of just using the object type from the beginning since you don't need the constructor type:
export class Thing{
name: string = "dunno"
}
export interface IMakeThing<T>{
value: T
}
const owner = new Thing();
const test: IMakeThing<Thing> = {
value: new Thing
};
If you actually mean to put the constructor function under value
, then just pass Thing
, not new Thing
, since new Thing
expands to new Thing()
:
export class Thing{
name: string = "dunno"
}
export interface IMakeThing<T extends new (...args: any) => any>{
value: T
}
const owner = new Thing();
const test: IMakeThing<typeof Thing> = {
value: Thing
};