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.
- By Michael Domingo
- 11/11/2016
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.