Paul Krill
Editor at Large

TypeScript 2.1 ups ease of use, adds expressive code

news
Dec 8, 20162 mins

The latest version of Microsoft's typed JavaScript superset picks up down-level async functions and mapped types

Microsoft released TypeScript 2.1 Wednesday with upgrades that reduce the friction of starting new projects, more powerful type-checking, and tools to write more expressive code.

TypeScript is a typed superset of JavaScript compiling to plain JavaScript. A release candidate of version 2.1 arrived about a month ago.

Down-level async functions in version 2.1 let developers use async/await and target ECMAScript 3 and 5 without requiring any other tools. Users can write code around promises while not having to use callbacks. “Bringing down-level async/await to TypeScript involved rewriting our emit pipeline to use tree transforms. Keeping parity meant not just that existing emit didn’t change, but that TypeScript’s emit speed was on par as well,” said Daniel Rosenwasser, Microsoft program manager for TypeScript.

Version 2.1 adds mapped types, which are produced by taking a union of literal types and computing properties for a new object type. “They’re like list comprehensions in Python, but instead of producing new elements in a list, they produce new properties in a type,” said Rosenwasser. Developers using mapped types also no longer have to create new or partial read-only variants of existing types.

Object, rest, and spread functionality in TypeScript 2.1 make it easier to partially copy, merge, and pick apart objects. This capability is planned for ECMAScript 2017, Rosenwasser said. The upgrade also features a key of operator called Index type query that’s used like a query for keys on object types. “The dual of this is indexed access types, also called lookup types,” said Rosenwasser. “Syntactically, they look exactly like an element access, but are written as types.”

TypeScript 2.1 can be installed using NuGet, NPM, or the TypeScript 2.1 Installer for Visual Studio, after accessing Update 3.

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