TypeScript 2.0 goes beyond that and begins to push the envelope on what type systems can do. Recently I've been loving the combination of discriminated union types and nullable types. It means that you can have code like this:
function myFunction(x: number | null) {
if (x === null) {
return;
}
console.log(x + 1); // x is now a number
}
The argument to the function is x, which is either number or null (that's what number | null means). But the if statement ensures it's not null by exiting the function, so by the time you get to the log TypeScript has (correctly) set the type of x to be just number!The types match up exactly with how you'd write the Javascript code. It's awesome and it just works.