TypeScript 2.0

Null- and undefined-aware types TypeScript has two special types, Null and Undefined, that have the values null and undefined respectively. Previously it was not possible to explicitly name these types, but null and undefined may now be used as type names regardless of type checking mode. The type checker previously considered null and undefined assignable to anything. Effectively, null and undefined were valid values of every type and it wasn’t possible to specifically exclude them (and theref

TypeScript 1.8

Type parameters as constraints With TypeScript 1.8 it becomes possible for a type parameter constraint to reference type parameters from the same type parameter list. Previously this was an error. This capability is usually referred to as F-Bounded Polymorphism. Example function assign<T extends U, U>(target: T, source: U): T { for (let id in source) { target[id] = source[id]; } return target; } let x = { a: 1, b: 2, c: 3, d: 4 }; assign(x, { b: 10, d: 20 }); assign(x, { e: 0 }

TypeScript 1.7

async/await support in ES6 targets (Node v4+) TypeScript now supports asynchronous functions for engines that have native support for ES6 generators, e.g. Node v4 and above. Asynchronous functions are prefixed with the async keyword; await suspends the execution until an asynchronous function return promise is fulfilled and unwraps the value from the Promise returned. Example In the following example, each input element will be printed out one at a time with a 400ms delay: "use strict"; // pr

TypeScript 1.6

JSX support JSX is an embeddable XML-like syntax. It is meant to be transformed into valid JavaScript, but the semantics of that transformation are implementation-specific. JSX came to popularity with the React library but has since seen other applications. TypeScript 1.6 supports embedding, type checking, and optionally compiling JSX directly into JavaScript. New .tsx file extension and as operator TypeScript 1.6 introduces a new .tsx file extension. This extension does two things: it enables

TypeScript 1.5

ES6 Modules TypeScript 1.5 supports ECMAScript 6 (ES6) modules. ES6 modules are effectively TypeScript external modules with a new syntax: ES6 modules are separately loaded source files that possibly import other modules and provide a number of externally accessible exports. ES6 modules feature several new export and import declarations. It is recommended that TypeScript libraries and applications be updated to use the new syntax, but this is not a requirement. The new ES6 module syntax coexist

TypeScript 1.4

Union types Overview Union types are a powerful way to express a value that can be one of several types. For example, you might have an API for running a program that takes a commandline as either a string, a string[] or a function that returns a string. You can now write: interface RunOptions { program: string; commandline: string[]|string|(() => string); } Assignment to union types works very intuitively – anything you could assign to one of the union type’s members is assignable to

TypeScript 1.3

Protected The new protected modifier in classes works like it does in familiar languages like C++, C#, and Java. A protected member of a class is visible only inside subclasses of the class in which it is declared: class Thing { protected doSomething() { /* ... */ } } class MyThing extends Thing { public myMethod() { // OK, can access protected member from subclass this.doSomething(); } } var t = new MyThing(); t.doSomething(); // Error, cannot call protected member from outside clas

TypeScript 1.1

Performance Improvements The 1.1 compiler is typically around 4x faster than any previous release. See this blog post for some impressive charts. Better Module Visibility Rules TypeScript now only strictly enforces the visibility of types in modules if the --declaration flag is provided. This is very useful for Angular scenarios, for example: module MyControllers { interface ZooScope extends ng.IScope { animals: Animal[]; } export class ZooController { // Used to be an error (cannot e

Types

Generic Types In previous sections, we created generic identity functions that worked over a range of types. In this section, we’ll explore the type of the functions themselves and how to create generic interfaces. The type of generic functions is just like those of non-generic functions, with the type parameters listed first, similarly to function declarations: function identity<T>(arg: T): T { return arg; } let myIdentity: <T>(arg: T) => T = identity; We could also have use

typeof type guards

typeof type guards Let’s go back and write the code for the version of padLeft that uses union types. We could write it with type predicates as follows: function isNumber(x: any): x is number { return typeof x === "number"; } function isString(x: any): x is string { return typeof x === "string"; } function padLeft(value: string, padding: string | number) { if (isNumber(padding)) { return Array(padding + 1).join(" ") + value; } if (isString(padding)) { return padding + value