TypeScript 2.1 Released
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.
object.assign to combine objects. The result is similar, but the spread operator dramatically reduces the amount of code needed and increases readability.
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.