TypeScript 2.1 pulls even more modern JavaScript features

Ngoc Huynh

The new version, now at the release candidate stage, features inference and sync improvements.

TypeScript, Microsoft’s typed superset of JavaScript, is getting set for an upgrade that will feature improved inference and async functions.

While Version 2.0 arrived in September, Microsoft already has a release candidate of version 2.1 that brings features from ECMAScript 2015 and later to JavaScript runtimes, said Daniel Rosenwasser, Microsoft program manager for TypeScript. It can be used with the Visual Studio Code editor or Microsoft’s Sublime plugin.

The upgrade enables easier modeling of scenarios where variables might be incrementally initialized. With a lot of JavaScript code already written in this manner, it will be easier to migrate existing code bases over to TypeScript, Rosenwaser said.

Also, TypeScript 2.1 builds on TypeScript 2.0’s use of control flow analysis to track types through a program. There will be deeper examination of the type of any variable that could be destined for a better type. With the improvement, types will be inferred based on whatever is assigned afterward.

Async/await, or downlevel async functions, is featured in the release candidate. It “allows users to write code around promises without needing to use callbacks,” Rosenwasser said. “Async functions can be written in a style that looks synchronous, but acts asynchronously, using the await keyword.” This capability was supported prior to version 2.1, but only when targeting ES2015. “TypeScript 2.1 brings the capability to ES3 and ES5 runtimes, meaning you’ll be free to take advantage of it no matter what environment you’re using,” said Rosenwasser.

Share the news now

Source : http://www.infoworld.com/