Paul Krill
Editor at Large

TypeScript 2.1 pulls even more modern JavaScript features

news
Nov 10, 20162 mins

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

typewriter typescript
Credit: Mira DeShazer

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.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author