-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Calling an overloaded function should resolve to best match, not first #48077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as off-topic.
This comment was marked as off-topic.
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. |
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 :) |
Bug Report
π Search Terms
function overload signature void promise
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
Autocomplete and hover show the first matching signature:
π Expected behavior
I would have hoped for the more precise signature:
More (Downstream) Details
This actually causes some issues in typescript-eslint's
no-misused-promises
rule. See typescript-eslint/typescript-eslint#4620: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
getResolvedSignature
API returns the() => void
overload instead first() => Promise<void>
seem unsafeOur workaround is to check all call signatures, which is imprecise and can lead to false negatives in cases like:
See standalone repro here: https://github.com/JoshuaKGoldberg/repros/tree/typescript-promise-returning-overload-resolve
I think this is different from #41563 because this issue also repros in 4.1.0-beta.
The text was updated successfully, but these errors were encountered: