-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Enable method signature completions for object literal that is implementing an interface #46590
Comments
This was a known limitation of the PR for 4.5, but probably won't be difficult to add in 4.6. |
@andrewbranch Should the completion of object literal elements be allowed with the |
@gabritto and I briefly discussed this when coming up with the name at the time. IIRC we didn’t really feel great about any options and mostly just lamented that we don’t have a way of presenting hierarchical preferences. One related thought is that for object literals we might want to give an option for whether to always use arrow function properties or to match the declaring interface—I personally tend to use arrow functions for object literal members even when the member is written as a method signature on the interface. If we do want to make that configurable, I think we would need a separate option. @gabritto @DanielRosenwasser @mjbvz what do you think? |
@andrewbranch I think we can surface these settings sort of hierarchically in VS Code if we want. Right now have
but we could expand this to something like:
We'd keep two distinct settings on the TS side, this would just be for the VS Code settings UI |
Let's make sure we decide on on this before 4.5 goes so I can rename the VS Code setting if needed |
@mjbvz that only affects the presentation of the setting title in the UI, right? This is better than nothing, but it still appears as a flat list and is kind of hard to navigate. But, properly organizing the data leaves room for UI improvements later. I like your suggestion for the setting name, though I’m now having stronger doubts about using the term “class” to control something for object literals as well. Maybe at that point we can do |
I think that change wouldn’t require any changes on the TS side right now; the new name can still map to the existing TS preference name. |
I agree with @andrewbranch, I think this is better than what we have now, but I think we want to have something more structured for these options in the future. Also, a few other things on my mind:
|
Agreed. And you’re right, there are other significant differences. Parameters are contextually typed in object literals so there’s no need to write their type annotations. Also, in a class member position you can be fairly sure that a user starting to type a method name intends to type a whole method declaration. Not so in object literals, where it is possible to write a property assignment to an existing function instead: import * as ts from "typescript";
const host: ts.LanguageServiceHost = {
fileExis/*|*/
}; At this location we have no heuristics that would indicate whether the user intends to write a function literal / method declaration or a property assignment: const host: ts.LanguageServiceHost = {
fileExists: ts.sys.fileExists,
}; so we cannot replace the completion containing just the |
Related to the arrow function discussion on SO, see How to make VS Code autocomplete a callable property to an arrow function instead of a regular function? |
Bug Report
🔎 Search Terms
🕗 Version & Regression Information
4.5.0-dev.20211029
💻 Code
For the code:
Trigger suggestions inside the object literal
🙁 Actual behavior
We get a suggestion for
bar
but accepting it only completesbar
🙂 Expected behavior
Accepting the completion for
bar
should also insert the method signature:The text was updated successfully, but these errors were encountered: