New Open Source TypeScript 2.5 Improves Code Refactoring, More
Microsoft last week said new code refactorings highlight the latest open source TypeScript 2.5 release, along with a host of other improvements.
In detailing the changes to version 2.5, Rosenwasser highlighted the new code refactoring functionality provided by extract method and extract function -- "two new refactorings that make complex rewrites trivial."
Basically, the features -- long available in some other languages -- let developers quickly extract code from existing blocks and quickly turn it into a new function or method.
One of those languages for which the extract functionality has long been available is C#, and its documentation explains more:
Extract Method is a refactoring operation that provides an easy way to create a new method from a code fragment in an existing member.
Using Extract Method, you can create a new method by extracting a selection of code from inside the code block of an existing member. The new, extracted method contains the selected code, and the selected code in the existing member is replaced with a call to the new method. Turning a fragment of code into its own method lets you quickly and accurately reorganize code for better reuse and readability.
Extract Method has the following benefits:
- Encourages best coding practices by emphasizing discrete, reusable methods.
- Encourages self-documenting code through good organization.
- When descriptive names are used, high-level methods can read more like a series of comments.
- Encourages the creation of finer-grained methods to simplify overriding.
- Reduces code duplication.
A comment on Rosenwasser's post said: "We expect extract method and extract function will be available in Visual Studio 2017 version 15.4."
Rosenwasser also detailed other improvements, including guidance about when developers might be doing something wrong -- for example, trying to use JSDoc-style types, which aren't valid in TypeScript. It will "suggest" changes to forestall errors. It also suggests alternative solutions for other issues, such as incorrectly referencing the type of a property off of another type.
Another new feature lets developers simplify try/catch blocks when they don't really care about any thrown errors because the problem can be addressed without even having to touch the error, so it doesn't need to be included as a parameter in the catch block.
Last week's post includes guidance on installing TypeScript 2.5 in different editors and IDEs. It's typically available for installation via NuGet or npm. Manual installation is also available for Visual Studio 2015 and Visual Studio 2017 15.2 or later. Code editors such as Visual Studio Code or Sublime Text can be immediately configured to use the new version 2.5.
Complete details are available in a "what's new" page. Future direction is unveiled in the product roadmap.
David Ramel is editor in chief of Visual Studio Magazine and Application Development Trends Magazine.