-
Notifications
You must be signed in to change notification settings - Fork 12.8k
IntelliSense shows incorrect parameter names (TypeScript) #31845
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
Also, weirdly, if you hover |
Confirmed with TS 3.6.0-dev.20190608 |
Possibly related: Playground link function frob<T, A extends any[]>(f: (...args: A) => T, ...args: A)
{
return f(...args);
}
function blub(foo: string, bar: number) {}
frob(blub, "banana slamma", 812); Parameter names are correct while typing out the call, but... once everything is totally filled out it reverts to generic |
@RyanCavanaugh can I have a look at this ? I dug around previously in the area (#30084) |
Sure! |
@RyanCavanaugh A smaller repro of this would be: let fn: (<U>(a1: U) => void) | (() => void)
fn(1) // quick info: let fn: <number>(arg0: number) => void The issue is that when the signatures in the union are combined, instead of using the only available name (ex: Possible Solutions:
Ex: let fn2: ((p1: { b: string }) => void) | ((p2: { a: number }) => void)
fn2({}) // quick info: let fn2(p1 & p2: { b: string; } & { a: number; }): void This is a bit of a whacky idea but it might be useful 🤷♀️ Should I just proceed with 1 ? Or experiment with 2 ? @fatcerberus The issue you found has a different root cause to the one in the original post, it might merit a ticket of its own. |
For my part I kind of like the second idea, when you have a union of functions it ends up requiring an intersection of arguments (by way of contravariance) which tends to throw people off especially if they're not used to seeing intersections in everyday code. So it might be good to provide a hint that the signature on display was in fact synthesized from two (or more) different functions. |
I am writing a helper function that provides functionality often associated with the traditional switch statement, but in a more functional style. In doing so, I have come across a bug.
Consider the following code, which is a simplification of the helper I'm writing:
When hovering the first
on
call, we see the expected information:However, when hovering the second
on
call, which is a call to theon
property of the result of eithermatch
ormatched
, we get:As we can see, the types are just fine, but the argument names are replaced with 'arg0' and 'arg1'. This in itself could be intentional for some reason, and hence not a bug, but here's what leads me to consider this a bug:
When removing the last argument to the second
on
call, IntelliSense gives us an error as expected, but with an error text containing one of the previously replaced argument names, 'outcome':The same goes for 'prediction' if both arguments are removed.
I suspect this might be a result of trying to derive the parameter names from the second definition of
on
(as a result of thematched
function), which would be inconsistent as the rest of the call signature is clearly derived from the first definition (as a result of thematch
function). Or I am completely wrong, which is also very much possible.Anyway, this is misleading. What I expect is for both the call signature and error text to contain 'prediction' and 'outcome' as the parameter names, or at the very least for these to be consistent.
PS: The full thing is at https://github.com/korkje/match/blob/master/src/index.ts, and exhibits the same weirdness.
The text was updated successfully, but these errors were encountered: