TypeScript 2.0 introduces two new types:
undefined. You have to set the compiler option
true to use these types. In this mode, all other types cannot contain
null anymore. If you want to declare a variable that can be
null, you have to annotate it with a union type. For instance, if you want a variable that should contain a
undefined, you can declare it as
let x: string | undefined;.
Before assignments, the type of the variable will be
undefined. Assignments and type guards will modify the type locally.
TypeScript has various ways to check whether a variable could be
null. The next code block demonstrates them: ...