I'm used to using webstorm to generate getter and setter for classes.
Is there any way to do it with VSCode in short steps?
In TypeScript, there are two supported methods getter and setter to access and set the class members.
You just simply press Alt + Ins in Android Studio. After declaring variables, you will get the getters and setters in the generated code.
Introduction to TypeScript Getters and Setters The getters and setters allow you to control the access to the properties of a class. For each property: A getter method returns the value of the property's value. A getter is also called an accessor. A setter method updates the property's value.
This feature is shipped builtin with Visual Studio Code 1.24 (May 2018); see here: https://code.visualstudio.com/updates/v1_24#_generate-gettersetter-refactoring
Basically you select the line with the property, then a Quick Action bulb is shown which you have to click. Then you can generate the getters/setters.
The shortcut is Ctrl+Shift+R after highlighting the property.
Longer method: Right click on the property. Then click on refactor from the popup menu.
Currently, vscode has no feature to mass generate getters and setters for all class properties at once like in other IDEs so it has to be done one property at a time.
A VS Code plugin that works to create Java style getters and setters (accessor and mutator methods) is Wilson Godoi's TypeScript's Getters and Setters Object Oriented Programming Style.
https://marketplace.visualstudio.com/items?itemName=Wilson-Godoi.wg-getters-and-setters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With