class Class {
}
const f0 = <T extends typeof Class> (c:T): T => {
return c
}
const call0 = f0 (Class) //ok
const f1 = <T extends typeof Class> (c:T): T => {
const a = new c()
return a //TS2322: Type 'Class' is not assignable to type 'T'. 'T' could be instantiated with an arbitrary type which could be unrelated to 'Class'.
}
const call1 = f1 (Class)
const f2 = <T extends typeof Class> (c:T):InstanceType<T> => {
const a = new c()
return a //TS2322: Type 'Class' is not assignable to type 'InstanceType '.
}
const call2 = f1 (Class)
The argument is typed as T, so why isn’t that acceptable for the return type?