How to dynamically instantiate a class of a specific generic type

Viewed 52

In the following example, I expected the type of the created object to be SpecificSomething<Error> but it turns out to be the base type, SpecificSomething<Error>

class Something<A> {}
class SpecificSomething<A> extends Something<A> {}

function createSomething<W extends Something<Error>>(ctor: { new(): W }): W {
    return new ctor;
}
const a = createSomething(SpecificSomething);

Why is a of type Something<Error> and not SpecificSomething<Error>? And how can I fix it?

Typescript Playground example

0 Answers
Related