-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Implicitly typed parameters of function properties of generic parameters break autocompletion #46916
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
Note for future investigators: The magic concept at play here is the "context-sensitive" expression // enabled: (str) => str.length > 0 which is somehow defeating our logic that gets completions in the face of an incomplete generic call |
There are different angles to this issue. I'm not sure if it's worth fixing this but perhaps a fix to this would improve some other, more compelling, scenarios. First of all, this signature doesn't make much sense to me. The type parameter is defined as While investigating this case we can learn that, in a case without context-sensitive functions, completions are provided based on the signature computed by So why do context-sensitive functions break this? They make all objects that contain them (recursively, up to the root object) non-inferrable. So when That is later used to obtain the So what could potentially be done about this?
|
I'm thinking about this more and more and I have a hunch that there might be something in that third idea. I imagine that each cc @andrewbranch maybe you'd be interested in this... am I completely delusional here or does this sound plausible? 😅 |
I believe @Conviley ran into the same issue. This is my (mostly) minimal reproduction of their issue: declare function makeRequest<
QueryParam
>(
getFn: (client: { prop: number }) => QueryParam,
params: NoInfer<QueryParam>,
): void;
// Hovering over `makeRequest` shows that `QueryParam` is inferred as `unknown` and `params` is obstensibly typed as `unknown` which is incongruous with this call is an error.
makeRequest(
(client) => client,
// Using autocomplete here suggests no property keys.
{},
// ^ Argument of type '{}' is not assignable to parameter of type '{ prop: number; }'.
);
makeRequest(
(client: { prop: number }) => client,
// Using autocomplete here now suggests keys.
{},
); @Andarist maybe you have a better understanding of whether internally this is the same thing or not? |
My intuition is this is different - even if only because this issue focuses so much on multi-step~ thing within a single argument object. That's usually a tell-tale that the issue is about intra-expression inferences. I think it might be connected to your issue - but fixing yours might be way simpler than fixing this one. At least that's my intuition. What happens here is that it fails to infer a correct signature here so it goes for I already played with removing this flag from there on like 2 occasions. While I don't remember exactly why I gave up... I do remember that it didn't break that much in the existing test suite. There were some hurdles there though and it didn't seem important enough to be bothered with it. I think I was mainly looking into fixing this weird discrepancy between the reported error and the inferred result that we can see here ( Fixing this for completions would be rather easy because the compiler could behave differently when resolving signatures for that - but fundamentally it would be better to try fixing the above again. |
I wonder if the issue described here is the same "issue" as the following (I don't think it is.. but it seems just a bit confusing). When I explicitly add a type to the return function, then type checking works as I'd like. But when the type is defined after the variable definition, then TS only checks if the type is compatible. I'd also like to know whether the inferred type from the anonymous function has some properties, that don't exist in the type
|
This is a different and it's a duplicate of #59586 |
Bug Report
🔎 Search Terms
generic parameter autocomplete
extends autocomplete
parameter breaks autocomplete
implicit parameter breaks autocomplete
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
No autocomplete inside
defineSteps({ ... })
after defining a function with an implicitly typed parameter in any ofenabled
properties. TS can't even get the parameter type implicitly on v3.3.3, so my guess is some stuff got improved which helped to infer the type, but there is something slightly wrong under the carpet, which causes this.🙂 Expected behavior
Getting autocomplete inside
defineSteps({ ... })
, even when I define a function with an implicitly typed parameter.The text was updated successfully, but these errors were encountered: