News
TypeScript 2.1 Is Done, But There's More
Following the RC release of 2.1 nearly a month ago, the final version adds a few more tweaks to smooth the coding experience.
- By Michael Domingo
- 12/07/2016
Following the TypeScript 2.1 release candidate that hit the Web nearly a month ago, the finalized version adds a few more tweaks to smooth the coding experience.
"This release comes with features that we think will drastically reduce the friction of starting new projects, make the type-checker much more powerful, and give you the tools to write much more expressive code," writes Microsoft Program Manager Daniel Rosenwasser, in a blog post. His post covers lots of ground: async functions, support for object rest & spread, lookup types, mapped types, more utility types, and easier package imports.
Async functions were a part of the 2.1 RC, but in this release it's been tested and stable when targeting ES3/ES5.
Rosenwasser notes that object rest & spread are part of the ES2017 proposal "that makes it much easier to partially copy, merge, and pick apart objects." Object spreads use the spread operator to streamline copying of properties from object to object, while object rests can be extracted into distinct variables.
TypeScript 2.1 also has support for lookup types and mapped types. "Mapped types are produced by taking a union of literal types, and computing a set of properties for a new object type," he writes. He also notes that with the addtion of mapped types, partial type operators aren't absolutely necessary. Even so, support for partial is incorporated into 2.1, as are several others: readonly, record and pick. Rosenwasser points to a Github lib.d.ts file that provides usage examples.
To reduce editing friction, version 2.1 automatically makes assumptions about packages that are installed, bypassing the need to declare them. "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," he said. Rosenwasser does caution that because of its more trusting nature, there's the assumption that installed package "has the type any, meaning you can do anything with it."
Rosenwasser's blog at the end also links to additional features, including support for custom elements and importing helper functions.
On a related note: Be sure to read Visual Studio Magazine columnist Peter Vogel's recent TypeScript 2.0 coverage on data typing and class discriminants.
About the Author
Michael Domingo is a long-time software publishing veteran, having started up and managed several developer publications for the Clipper compiler, Microsoft Access, and Visual Basic. He's also managed IT pubs for 1105 Media, including Microsoft Certified Professional Magazine and Virtualization Review before landing his current gig as Visual Studio Magazine Editor in Chief. Besides his publishing life, he's a professional photographer, whose work can be found by Googling domingophoto.