Skip to main content
Note: this page is a beta page, don't rely on the URL and file issues on microsoft/TypeScript-Website please

TypeScript 1.1

This is a test example, knowingly shipped to prod while v2 is in beta - it’s got a really long comment and a twoslash error.

ts
function longest<function longest<T extends { length: number; }>(a: T, b: T): TT (type parameter) T in longest<T extends { length: number; }>(a: T, b: T): Textends { length:(property) length: number number }>(a:(parameter) a: T extends { length: number; } T,(type parameter) T in longest<T extends { length: number; }>(a: T, b: T): T b:(parameter) b: T extends { length: number; } T)(type parameter) T in longest<T extends { length: number; }>(a: T, b: T): T { if (a.(parameter) a: T extends { length: number; }length (property) length: number>= b.(parameter) b: T extends { length: number; }length)(property) length: number { return a(parameter) a: T extends { length: number; } } else { return b(parameter) b: T extends { length: number; } } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // longerArray is of type 'number[]' const longerArray const longerArray: number[]= longest(function longest<number[]>(a: number[], b: number[]): number[]1, 2], [1, 2, 3]) // longerString is of type 'string' const longerString const longerString: "alice" | "bob"= longest(function longest<"alice" | "bob">(a: "alice" | "bob", b: "alice" | "bob"): "alice" | "bob"'alice', 'bob') // Error! Numbers don't have a 'length' property const notOK const notOK: { length: number; }= longest(function longest<{ length: number; }>(a: { length: number; }, b: { length: number; }): { length: number; }10, 100) Argument of type '10' is not assignable to parameter of type '{ length: number; }'.2345Argument of type '10' is not assignable to parameter of type '{ length: number; }'. const hello const hello: "alice" | "bob"= longest(function longest<"alice" | "bob">(a: "alice" | "bob", b: "alice" | "bob"): "alice" | "bob"'alice', 'bob') console.var console: Consolelog((method) Console.log(message?: any, ...optionalParams: any[]): voidhello)const hello: "alice" | "bob"

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:

ts
module MyControllers { interface ZooScope extends ng.IScope { animals: Animal[] } export class ZooController { // Used to be an error (cannot expose ZooScope), but now is only // an error when trying to generate .d.ts files constructor(public $scope: ZooScope) {} /* more code */ } }