News

TypeScript 2.1 Is Now Smarter Than Ever

It's like a better version of TypeScript 2.0, only this incremental update adds "smarter" inference and a bevy of other improvements.

New this week is a version of TypeScript 2.1 that follows the version 2.0 release of nearly a month ago, only this one is naturally better. It's better in that it adds "smarter" inference for better tooling and a handful of small but important improvements to try out.

"TypeScript 2.1 now makes it easier to model scenarios where you might incrementally initialize variables," writes Microsoft Program Manager Daniel Rosenwasser, in a blog. "Since a lot of code is written like this in JavaScript, this makes it even easier to migrate existing codebases to TypeScript."

Rosenwasser holds up the any type as an example in his post: TypeScript will assign an implicit any type to a variable if one isn't assigned to it. That's all well and good with earlier versions, but he said that "[w]ith TypeScript 2.0 we built out a foundation of using control flow analysis to track the flow of types throughout your program. Because that analysis examines the assignments of every variable, we've leveraged that same foundation in TypeScript 2.1 to more deeply examine the type of any variable that seems like it's destined for a better type." So, TypeScript no longer assigns any to a variable, but smartly infers the variable's type based on what you assign to it.

TypeScript 2.1 also has support for async/await. If this capability looks familiar, Rosenwasser notes that it has existed in earlier versions of TypeScript that were used to target ES6 and ES 2015. "TypeScript 2.1 brings the capability to ES3 and ES5 runtimes, meaning you'll be free to take advantage of it no matter what environment you're using," he writes.

On a side note, on the GitHub page for TypeScript there's also a nifty roadmap of features coming in subsequent releases. The notes shows that support for project references, addition of variadic types and partial types, and support for type-checking of computed properties for constants and symbols are expected in the next update.

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