Q:

Generic constraint on constructor function

function createInstance<T>(t: new () => T): T {
    return new t();
}

class Test {
    x: number = 4;
}

let test: Test = createInstance(Test);
console.log(test);
0

New to Communities?

Join the community