Typescript Destructure PluginThis TypeScript Language Service Plugin provides a set of source actions that simplify object destructuring as well as folding specific properties in rest operator. Also available as an extension for VSCode. 🚧 Warning: this package is now in alpha stage, so it may contain formatting bugs. Please file an issue if you encounter any strange behavior 💜 🚧 WhyThere is a common style of coding in Javascript/Typescript when you get an object argument for a function input and destructure it, either in the first statement or directly in the arguments. Destructuring is especially popular in React Community. This plugin is designed to help you save time spent copying properties from the object. How to useAlmost all source actions (except for the collapse into rest operator) provided by the plugin become available when you set the cursor on or highlight the variable which can be destructured. When this condition is met, a lightbulb will appear next to the desired line (check the Note about union types: destructuring source actions are not available for union types since it' s impossible to understand what type of union you need to destructure. In this case, you should help the compiler by removing unnecessary types from the union:
FeaturesCreate destructuring assignmentCreates a variable with destructuring assignment of the object fields.
DemonstrationDestructure function parameterReplaces the function argument with destructurization.
DemonstrationDestructure object propertySince all source actions in this plugin destructure an object only one level deep, it would be good to have a tool for unfolding specific properties. And that's what it is.
DemonstrationCollapse into rest operatorCollapses the selected properties into new variable with the rest operator. Reuses an existing rest variable if any exists, or creates a new one.
DemonstrationUnfold the rest operatorContrary to the previous one: expands rest operator into separate variables.
Demonstration |