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
declarefunctionoverloaded(x: number): number;declarefunctionoverloaded(x: string): string;declarefunctionwonky<T>(value: T,func: (x: T)=>T): void;wonky(1,overloaded)// ^-- Argument of type 'number' is not assignable to parameter of type 'string'.// Maybe shouldn't resolve a type from a function with overloads unless there's// no other option?
It's not pretty, but it can be worked around by forcing T to be inferred from value.
Duplicate #32418; generic inference is limited to "last overload" in most cases. Overloads, whenever possible, should always have a final overload that covers all of the cases in a more general way.
TypeScript Version: 4.0.2
Search Terms:
Expected behavior:
T
gets inferred fromvalue
, should resolveoverloaded
to the most appropriate signature ((x: number) => number
)Actual behavior:
T
is inferred from final signature ofoverloaded
.Related Issues:
Code
It's not pretty, but it can be worked around by forcing
T
to be inferred fromvalue
.Output
Compiler Options
Playground Link: Provided
The text was updated successfully, but these errors were encountered: