Facilitating the spread of knowledge and innovation in professional software development

Contribute

### Topics

InfoQ Homepage News TypeScript 2.1 Released

# TypeScript 2.1 Released

Leia em PortuguÃªs

This item in japanese

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.

## How might we improve InfoQ for you

Thank you for being an InfoQ reader.

Each year, we seek feedback from our readers to help us improve InfoQ. Would you mind spending 2 minutes to share your feedback in our short survey? Your feedback will directly help us continually evolve how we support you.

Style

## Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.