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.
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.
Sign up for CIO Asia eNewsletters.