One of the big additions promised for 2.0 -- non-nullable types -- is being delivered. Pass a flag to TypeScript and it will ensure that, for instance, strings or numbers never end up being assigned to
undefined. In cases where you want something to be given those values,
undefined are now available as types.
In cases where you want to override the type system's protections, Microsoft allows a way to conditionally override it. Add "
!" as a postfix to any variable (such as
user_name!), and TypeScript will assume the variable in question doesn't need to be guarded against
Not all of 2.0's additions revolve around types; some deal with the workflow around a script. Module declarations, for example, are easier to write this time around. A developer in a hurry can start with a stub declaration that has no actual code in it or even declare a whole package of modules in this fashion.
What's missing from 2.0 -- for now -- is support for
await. These keywords were introduced in ECMAScript 2016 to make asynchronous programming easier, in the same manner as similar keywords for C#, Dart, and Python. One boon is that TypeScript code written with
Microsoft's beta notes indicate that the main reason for the delay in support was to make sure TypeScript could generate the needed
await code quickly enough, and to thoroughly test the resulting behaviors. "While we feel confident in today's implementation, confidence is no match for thorough testing," Microsoft wrote.
As a result,
await support has been bumped to the 2.1 release.