-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Unexpected overload signature is matched with constructor type #51899
Copy link
Copy link
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
Bug Report
🔎 Search Terms
overload, constructor type
🕗 Version & Regression Information
I tested with different TS v4 versions. This bug does not seem like a regression.
⏯ Playground Link
Playground link with relevant code
💻 Code
type Type<T> = new (...args: any[]) => T;
function inject<T>(t: Type<T>): T;
function inject(t: any): any; // comment out this line => the type of `c2` will be `ClassWithCtorArgs`
function inject(t: any): any {
return t;
}
class Class {}
class ClassWithCtorArgs {
constructor(x: number) {}
}
// type: Class ✅
const c1 = inject(Class);
// type: any ❌
const c2 = inject(ClassWithCtorArgs);🙁 Actual behavior
The type of c2 constant from the example is any.
🙂 Expected behavior
The type of c2 constant from the example should be ClassWithCtorArgs.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug