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.

Originally developed and still stewarded by Microsoft after being donated to the open source community (source code is on GitHub), TypeScript is a strict syntactical superset of JavaScript -- with the addition of optional static typing functionality. As it compiles to plain old JavaScript, its tagline says it can be used on any browser and any host on any OS.

"Static types can make it easier to maintain your code by catching bugs early on, making it easier to navigate your projects, giving accurate code completion, and providing handy fixes for when you do make mistakes," said Microsoft's Daniel Rosenwasser in an introductory blog post last week. "By making types optional, you can get the flexibility of plain JavaScript when you need it, all while TypeScript also gives you the option to tighten things up to bring you more type safety."

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.

About the Author

David Ramel is an editor and writer for Converge360.

comments powered by Disqus


  • Visual Studio Code Dev Team Cleans Up

    The Visual Studio Code development team focused on some housekeeping in the October update, closing more than 4,000 issues on GitHub, where the cross-platform, open-source editor lives.

  • ML.NET Model Builder Update Boosts Image Classification

    Microsoft announced an update to the Model Builder component of its ML.NET machine learning framework, boosting image classification and adding "try your model" functionality for predictions with sample input.

  • How to Do Naive Bayes with Numeric Data Using C#

    Dr. James McCaffrey of Microsoft Research uses a full code sample and screenshots to demonstrate how to create a naive Bayes classification system when the predictor values are numeric, using the C# language without any special code libraries.

  • Vortex

    Open Source 'Infrastructure-as-Code' SDK Adds .NET Core Support for Working with Azure

    Pulumi, known for its "Infrastructure-as-Code" cloud development tooling, has added support for .NET Core, letting .NET-centric developers use C#, F# and VB.NET to create, deploy, and manage Azure infrastructure.

  • .NET Framework Not Forgotten: Repair Tool Updated

    Even though Microsoft's development focus has shifted to the open-source, cross-platform .NET Core initiative -- with the aging, traditional, Windows-only .NET Framework relegated primarily to fixes and maintenance such as quality and reliability improvements -- the latter is still getting some other attention, as exemplified in a repair tool update.

.NET Insight

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.

Upcoming Events