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

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 longestfunction longest<T extends { length: number; }>(a: T, b: T): T<T(type parameter) T in longest<T extends { length: number; }>(a: T, b: T): T extends { 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 longerArrayconst longerArray: number[] = longestfunction longest<number[]>(a: number[], b: number[]): number[]([1, 2], [1, 2, 3]) // longerString is of type 'string' const longerStringconst longerString: "alice" | "bob" = longestfunction longest<"alice" | "bob">(a: "alice" | "bob", b: "alice" | "bob"): "alice" | "bob"('alice', 'bob') // Error! Numbers don't have a 'length' property const notOKconst notOK: { length: number; } = longestfunction 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 helloconst hello: "alice" | "bob" = longestfunction longest<"alice" | "bob">(a: "alice" | "bob", b: "alice" | "bob"): "alice" | "bob"('alice', 'bob') consolevar console: Console.log(method) Console.log(message?: any, ...optionalParams: any[]): void(helloconst 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:

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 */
  }
}