TypeScript 2.1 ups ease of use, adds expressive code

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

TypeScript 2.1 ups ease of use, adds expressive code
Jimee, Jackie, Tom & Asha (CC BY-SA 2.0)

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.

Copyright © 2016 IDG Communications, Inc.

InfoWorld Technology of the Year Awards 2023. Now open for entries!