I've been struggling with an issue for a while now
consider the following:
export abstract class abstractClass {
abstract thing(): string
}
export class c1 extends abstractClass {
thing(): string {
return "hello"
}
}
export class c2 extends abstractClass {
thing(): string {
return "world"
}
}
export interface simpleInter {
el: typeof abstractClass
}
const cls: simpleInter[] = [];
cls.push({
el: c1
},{
el: c2
})
for (const classObj of cls) {
const c = new (classObj.el)() // error: Cannot create an instance of an abstract class. ts(2511)
console.log(c.thing())
}
What baffles me is how can I instruct the compiler to recognize that I want classes which extend my abstractClass
as the type.