TypeScript 2.1 pulls even more modern JavaScript features

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

TypeScript 2.1 pulls even more modern JavaScript features
Credit: Pixabay

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.

 TypeScript has been making significant waves lately. It has served as the basis for a recent rewrite of the Angular JavaScript framework, and it was cited this week as an inspiration for a potential type system in JavaScript itself. Future plans for TypeScript call for supporting type-checking of computed properties for constants and Symbols, backing for project references, and providing types to variadic functions. Bundling of TypeScript module type definitions, enabling a library to be consumed with a single TypeScript file; partial types backing; and refactoring support in TypeScript's Language Service API are on the drawing board as well. Nominal, or non-structural, typing support will be investigated, enabling developers to have more refined types.

To comment on this article and other InfoWorld content, visit InfoWorld's LinkedIn page, Facebook page and Twitter stream.
From CIO: 8 Free Online Courses to Grow Your Tech Skills
Notice to our Readers
We're now using social media to take your comments and feedback. Learn more about this here.