You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unexpected overload signature is matched with constructor typeΒ #51899
typeType<T>=new(...args: any[])=>T;functioninject<T>(t: Type<T>): T;functioninject(t: any): any;// comment out this line => the type of `c2` will be `ClassWithCtorArgs`functioninject(t: any): any{returnt;}classClass{}classClassWithCtorArgs{constructor(x: number){}}// type: Class β constc1=inject(Class);// type: any βconstc2=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.
The overload resolution algorithm is deliberately very simple. It proceeds as follows:
Pick the first signature which matches according to the subtype relation
If none was chosen, pick the first signature which matches according to the assignability relation
One of the differences between subtype and assignable is how any gets treated in function parameters, as shown here, so the second overload gets picked during the first pass.
I recommend using a different definition of Type<T>:
Activity
RyanCavanaugh commentedon Dec 15, 2022
The overload resolution algorithm is deliberately very simple. It proceeds as follows:
One of the differences between subtype and assignable is how
anygets treated in function parameters, as shown here, so the second overload gets picked during the first pass.I recommend using a different definition of
Type<T>:markostanimirovic commentedon Dec 15, 2022
Thank you so much Ryan Cavanaugh (@RyanCavanaugh)! :)