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
Calling an overloaded function should resolve to best match, not firstΒ #48077
When someone calls it( like above, we'd want to be able to check the precise resolved signature for the call to know whether they're dangerously passing a () => Promise<void> to an argument that takes () => void
The type checker getResolvedSignature API returns the () => void overload instead first
That overload would make calls that provide () => Promise<void> seem unsafe
Our workaround is to check all call signatures, which is imprecise and can lead to false negatives in cases like:
declareconstit: {(syncName: string,callback: ()=>void): void;(asyncName: number,callback: ()=>Promise<void>): void;};// We'll see that an overload exists that has callback: () => Promise<void>.// Without knowing it's the specific resolved one for this call,// we'll consider the call safe (even though it's not)it('',async()=>{});
Aha, thank you - I had forgotten/missed that. I guess changing it would be a pretty breaking change - will close this issue and instead work on fixing the Mocha type definitions. Cheers!
We tried various "best" algorithms at first, and they were just disasters, even before generics were in the mix. Ask the C# team about overload resolution if you want to hear a rant :)
Activity
JoshuaKGoldberg commentedon Mar 1, 2022
tjjfvi commentedon Mar 1, 2022
MartinJohns commentedon Mar 2, 2022
This is not a bug, it's working as intended. You're supposed to write the order of signatures from most specific to least specific. https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html#ordering
You might want to rephrase it as a feature request instead of a bug report.
JoshuaKGoldberg commentedon Mar 2, 2022
Aha, thank you - I had forgotten/missed that. I guess changing it would be a pretty breaking change - will close this issue and instead work on fixing the Mocha type definitions. Cheers!
RyanCavanaugh commentedon Mar 2, 2022
We tried various "best" algorithms at first, and they were just disasters, even before generics were in the mix. Ask the C# team about overload resolution if you want to hear a rant :)