-
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
Declare all missing members quick fix #28491
Comments
Any update on this, this would be very helpful. |
Do we have any updates on this? |
I've made a typescript language server plugin and vscode extension that adds some of this functionality. If this github issue gets approved with Help Wanted I'd be happy to whip up a PR Update: I've made this extension a bit more comprehensive now and it should be working for a lot more use cases. Features:
Some basic examples: |
@DanielRosenwasser It seems this issue has many reactions :). I think |
Seems like you'd need to reconstruct the information about which object literal is causing the missing properties issue. If you can get that object literal, you can totally imagine something where:
|
I would definitely love this feature too, just a quick fix to fill everything in would definitely be nice. That said, for anyone looking for this feature there is a way of doing it now though it's not as easy as a quick fix to fill everything in. VSCode has a command called "Trigger Suggest" that's used to show typeahead suggestions based on the current code context. In the case of missing type definitions of an interface, because the compiler knows the type definition and what's currently missing you can use the suggestion trigger to get the list of suggested properties. You can trigger this either from the command pallet or from the keyboard shortcut Definitely not as nice as a quick fix that shortcuts all of the properties for you, but still helpful. |
@DanielRosenwasser Could something like the extension I posted above be useful? It doesn't check for variables in scope to use as a shorthand, but I could spend a bit of time looking into that. For your 3rd point, it instead gives you a default value. e.g if the property is of type number, it will make a property declaration of I'm keen on starting a PR if this is something the TS team would be happy with! Edit: This is all implemented in the extension I posted above. Still very keen to do a PR if the team's happy with the approach. |
Thanks @a-tarasyuk! |
For extremely nested/deep object types, this QF would do too much, especially if you are passing references to other objects around. Example: you have a Of course, this is context-specific, so I suggest a second QF: "Declare all missing members (shallow)". There is a VSCode extension that does the same, here was my feedback: tamj0rd2/ts-quickfixes#183 |
In #28298 we added a new message that elaborated on several of the missing properties in a type. We should specialize the fix here.
The text was updated successfully, but these errors were encountered: