Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News TypeScript 2.1 Released

TypeScript 2.1 Released

Leia em Português

This item in japanese

Lire ce contenu en français

Microsoft has released TypeScript 2.1, bringing a slew of features that reduce unnecessary typing and streamline the toolchain.

Prior to this release, TypeScript supported async/await, but only when targeting ES2015. This worked well if the code was destined to live only in an advanced environment, but incomplete for those developing for all browsers in the wild. Developers had to add an additional transpiler (like Babel) to their toolchain in order to convert the code into a usable state for all browsers.

With 2.1, TypeScript can emit async/await into ES3/ES5 level code, making the need for Babel unnecessary.

For TypeScript developers working in React, the lack of the spread operator has meant changing code or adding in Babel to handle it. In React, the spread operator is often used when passing properties to a downlevel component or when mutating state. To do so in pre-2.1, TypeScript required adding Babel to handle the transform. The spread operator is useful in other ways as well, but without it, developers need to use the JavaScript feature object.assign to combine objects. The result is similar, but the spread operator dramatically reduces the amount of code needed and increases readability.

While async/await and the spread operator have been available in Babel for a while, TypeScript Program Manager Daniel Rosenwasser says the delay for 2.1 was due to making sure the typing system continued to work as expected:

When we implement a feature in TypeScript, we take lengths to ensure that it is typed appropriately and that its performance characteristics are reasonable. That means that when using object rest/spread, we didn't want to just ship an experience where type is effectively any, leading users to be frustrated if they make an error. With async/await, we had to rewrite our emit pipeline, which meant that we needed to keep parity in both output as well as time to emit. The investment has shown, and TypeScript is still extremely fast.

In the TypeScript 2.1 Announcement, Rosenwasser goes through many other new features such as the keyof operator, easier imports, and mapped types. Rosenwasser says that mapped types are "definitely the most interesting feature in TypeScript 2.1", by saving developers from having to make entirely new variants of existing objects when the properties are mostly the same. On improving the imports experience, Rosenwasser says that the solution was becoming more flexible:

We decided that TypeScript needs to be more trusting, and in TypeScript 2.1, so long as you have a package installed, you can use it.

TypeScript 2.1 is available in all the typical channels.

Rate this Article