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
Editor changes overload resolution based on syntax #58300
Comments
I gave this a try with a different syntax for overloads: declare function bar(
...args: [arg0: string, arg1: number, arg2: boolean] | [arg0: number, arg1: boolean, arg2: string] | [arg0: boolean, arg1: string, arg2: number]
): void; This example is even worse. The editor correctly finds the 3 overloads, but |
The difference lies in how |
I don't think it's really possible to define what the "correct" overload is for an argument set that doesn't match anything. When the parens are still open it makes sense to pretend the future params might be there, but when it's closed, well, who can say what kind of mistake you're making. For example, if there's an overload of one parameter of type |
@RyanCavanaugh not really sure I agree with you. "oo" doesn't match "foo", so why would you show me "foo"? Overload matching should be best effort matching, no? In my example, the argument list isn't done, because the comma is indicating I intend to add more arguments. Not adding another argument is a syntax error. Removing the comma is a compiler error. In either of these choices, it's an invalid call. Why complicate things by not even telling me what the next argument should be? |
In cases where you have trailing commas in an argument list, you'd have a compiler error if you couldn't find the right overload, so I'd agree here that it wouldn't matter which overload you show. declare function foo(x: number): void;
declare function foo(x: "foo"): void;
foo(
"oo", // error: No overload matches this call.
) But this is a specifically talking about functions with one parameter. The main issue I'm trying to outline in my example is that there are multiple parameters, with a correct first argument, yet the overload is not resolved/narrowed. |
This issue has been marked as "Not a Defect" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
π Search Terms
editor overload syntax
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?ts=5.4.5#code/CYUwxgNghgTiAEAzArgOzAFwJYHtVJxwAoAoeeWAcwAYAueAZwxi1UoBoKZKBGe1ZAFsARiBicqAJnrDCEEFFTsSASnoA3HFmABuEqEiwEKdNjwFiZLjX5DR4633iyc8xRO7TGzVh1UatXX1waDgkNExcfERCUnIqOmc5BSVHeiYWNg9KLwERMWU1eE1tPRIY4gBWIA
π» Code
π Actual behavior
foo
- note overload 2 is selected correctly by the editorfoo
with a closing parenthesis.Why does the presence of the closing parenthesis "break" the overload resolution?
π Expected behavior
The correct overload is resolvable and should be chosen by the editor.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: