The beta follows an announcement in April which confirmed that non-nullable types would be included. The new version has two types, one that has a single undefined value, and another that is called null type. A number and a string is undefined, a Union Type that can join single and null types. “If you want to have a thing that can be number or undefined, you write it as a union type,” Hejlsberg said.
Control Flow Analysis for Types
TypeScript's support for handling nullable types is possible thanks to changes in how types are tracked throughout the program. In 2.0, we've started using control flow analysis to better understand what a type has to be at a given location.
Easier Module Declarations
Sometimes you want to just tell TypeScript that a module exists, and you might not care what its shape is. We made it easier and got rid of the boilerplate. Now you can import any path that starts with
foo/ and TypeScript will assume it exists. You can take advantage of this if your module loader understands how to import based on a certain pattern too. Now whenever you import a path ending with
!text, TypeScript will understand that the import should be typed as a
undefined were in the domain of every type. That meant that if you had a function that took a
string, you couldn't be sure from the type alone of whether you actually had a
string – you might actually have
null. In TypeScript 2.0, the new
--strictNullChecks flag changes that.
string just means
To start implementing these new features you need to download the latest TypeScript 2.0 Beta for Visual Studio 2015. Those that are new to the subset can view the official documentation, which walks you through the building of a simple web application.