Typescript Destructure Plugin
This 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 💜 🚧
This plugin is designed to help you save time spent copying properties from the object.
How to use
Almost 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:
Create destructuring assignment
Creates a variable with destructuring assignment of the object fields.
Destructure function parameter
Replaces the function argument with destructurization.
Destructure object property
Since 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.
Collapse into rest operator
Collapses the selected properties into new variable with the rest operator. Reuses an existing rest variable if any exists, or creates a new one.
Unfold the rest operator
Contrary to the previous one: expands rest operator into separate variables.