-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Show errors from all overloads if no overload was matched #20139
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
That is the crux of the issue.. knowing what is a "closest" match. It is easy for a human to do that, but a bit hard to encode in an algorithm. we are open to suggestions for improving the user experience, if you would like to take a stab at enhancing the error reporting would be happy to take a PR. I should note that adding all errors is not helpful. first it is confusing by itself adding unrelated errors, so there has to be some context, e.g. Duplicate of #16793 |
Worth noting that some declaration files describe literally dozens of overloads for certain functions, so the worst-case behavior here would be completely inscrutable |
I would argue that it's less confusing than what we sometimes do right now, which is to show an error message relating to an overload we weren't trying to use.
True, but in the case of dozens of overloads, our current strategy of choosing the last overload is extremely unlikely to output a useful error message. I can see how printing errors for all overloads could be annoying in some cases, so maybe we can at least attempt to find a "best match". I'm thinking we could add some logic that works like this, in this order:
It's not perfect, but it should at least be better than the current behavior. |
I don't think displaying all possible overloads gets too messy if the error messages are properly formatted (possibly with colors and/or markers). As an example, in the C++ world both gcc and clang show all alternatives (don't know about other compilers), e.g: #include <vector>
template<typename T>
void foo(const T&, int) {};
template<typename T>
void foo(const std::vector<T>&, int) {};
template<typename T>
void foo(const T&, char) {};
int main(int, char**) {
foo(123, "abc");
} A possible diagnostics pattern for TS can be something like:
The empty lines between each overload can really reduce the "bloated feeling" when there are many overloads. Edit: maybe make it clear the used generic types in the diagnostics like clang does. For example:
or
|
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
Uh oh!
There was an error while loading. Please reload this page.
TypeScript Version: 2.7.0-dev.20171118
Code
Expected behavior: Typescript should fail with the error:
Actual behavior: Typescript fails with the error:
This is unhelpful. I was clearly going for the first overload, but I made a typo in the property name (or maybe the "c" property used to exist but was deleted). I think if typescript fails to find a match for any overload, it should display errors for all overloads with the same number of parameters. Something like:
If that's not possible for some reason, or if it seems too verbose, then we should at least display the error for the closest match, instead of always showing the last overload.
The text was updated successfully, but these errors were encountered: