Bug Report
I'm trying to write a function that takes a (generic) constructor and calls it to instantiate a class. The type inference for such a function normally works fine, but if the constructor is for a generic class it fails even if the generic parameter has a default.
🔎 Search Terms
generic constructor parameter inference instanceof
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about constructor parameters
⏯ Playground Link
Playground link with relevant code
💻 Code
class Foo<K extends {} = {}> {}
function create<T>(type: new () => T): T {
return new type();
}
let string = create(String); // has type String
let foo = create(Foo); // should have type Foo<{}>, has type unknown
🙁 Actual behavior
The foo variable has type unknown.
🙂 Expected behavior
I expected the foo variable to have type Foo<{}>.