![]() ![]() The new inspection will check that all the cases are covered and if any are missing, the intention to create them can be used. There’s now code completion inside switch that suggests cases based on the available data about the parameter (when it is a TypeScript enum or when its type is specified in JSDoc as a list of string values). We’ve added a bunch of improvements which may be truly beneficial to handling switch statements in JavaScript and TypeScript. But what if you edited your code and are now missing a new case inside the switch statement? Or there’s a missing default? Or what if some branches are unreachable? The IDE can now help with that too. WebStorm 2018.2 added an intention which generated cases for ‘switch’. With this handy new intention (Alt-Enter), you can replace properties defined in a constructor with class fields: // Before: Return fetch('').then( result => result.ok)Ĭonvert properties in constructor to class fields In this example, WebStorm knows that `fetch` returns a promise and suggests converting the download function to async: // Before: WebStorm will introduce a new variable and replace Promise.catch with the try-catch block: // Before: Simply press Alt-Enter on the name of the function and select Convert to async function. catch() calls to an async function that uses the async/await syntax – not only in TypeScript files, but also in JavaScript and Flow. With this new intention in the IDE, you can automatically change a function that returns a promise with. There’s also a new Convert parameters to object action (Alt-Enter) that generates a destructuring parameter for a function: For example, the Insert ‘require()’ quick-fix that works in Node.js apps with CommonJS modules now uses destructuring: Some other IDE actions now also default to destructuring. This intention can be very handy when working with React class components: If you want to keep the original assignments, you can use the Introduce object or array destructuring intention ( Alt-Enter), or go with the Extract object or array destructuring refactoring: If not all values from the array or object are used, the resulting destructuring will skip the elements: If you have a piece of code in which you are getting multiple values out of an array or an object, you can now simplify it by using the new Replace with object or array destructuring intention ( Alt-Enter): Let’s see how they can be used when working with objects and arrays. To help you start using destructuring in your code, WebStorm 2019.1 adds a set of new refactorings and intentions that can introduce destructuring to your code. ![]() If you’re not yet familiar with destructuring, we recommend reading the great overview in the book Exploring ES6. This feature has a very concise syntax that is often used when you need to pass data in your app. With destructuring, you can unpack values from arrays and objects into variables. JavaScript and TypeScript support Destructuring in JavaScript and TypeScript Version Control: cherry-pick a file from a commit from the VCS log incoming and outgoing commits. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |