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.

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.

comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube