Announcing TypeScript 0.9

Announcing TypeScript 0.9

Rate This
  • Comments 36

Today, we’re excited to be releasing TypeScript 0.9.0.  This release represents the largest update to TypeScript to date, bringing significant changes to the language, compiler and tools.  These span from highly requested new language features like Generics, to a new compiler infrastructure that lays the foundation for TypeScript tools scalability, to hundreds of bug fixes and general improvements.

TypeScript, since its release in October last year, has helped teams write large applications for the web, server, and Windows desktop.  TypeScript's lightweight type system is proving itself to be an effective way of providing tooling and early error detection that makes programming these large applications easier and safer than before. 

This release marks the first step of the 0.9.x series, introducing most of the new capabilities of this series which will be further refined over the next few months based on your feedback.  With today’s release, we’ve made a big step forward on the road to TypeScript 1.0.

Check out the downloads page to take TypeScript 0.9 for a spin today, take a look at the breaking changes list for help moving code forward to the new compiler, and send us your feedback on typescript.codeplex.com.

TypeScript 0.9 Language      

TypeScript 0.9 addresses many of the most highly requested language asks we’ve heard over the last 8 months.  Many of these improvements are targeted at furthering TypeScript’s commitment to enabling accurate and faithful descriptions of JavaScript API patterns.  Through community projects like DefinitelyTyped, we’ve seen a great ecosystem of library typings emerge, which has helped identify where the language changes could be most valuable.

Complete details of the TypeScript 0.9 language are available in the TypeScript specification.  Highlights include:

Generics

The most highly requested feature by 0.8 users, generics enable capturing relationships between inputs and outputs in APIs, enabling richer type checking for better error reporting and tools.  For example, generics allow the typing of the Array#map function from JavaScript to relate the element type of the array with the parameter to the callback function (‘T’ below), and the return type of the callback function with the return type of ‘map’ (‘U’ below).

    interface Array<T> {
        // ...
        map<U>(callbackfn: (value: T, index: number, array: T[]) => U): U[];
// ...
}

var array: Array<string> = ["John", "Sam", "George"];

var lengths = array.map((val, idx, arr) => val.length);

In many cases, the type arguments can be inferred, as in the call to array.map above.

Overloading on Constants

Many JavaScript APIs use strings parameters whose values determine the type returned by the API.  Overloading on constants enables TypeScript to capture this pattern and others like it.

    interface Document {
        createElement(tagName: string): HTMLElement;
        createElement(tagName: 'canvas'): HTMLCanvasElement;
        createElement(tagName: 'div'): HTMLDivElement;
        createElement(tagName: 'span'): HTMLSpanElement;
        // + 100 more
    }

The 0.9 release uses this technique to give more accurate type information for DOM functions like createElement, getElementsByTagName, addEventListener, and more.

Export =

TypeScript has built-in language support for external module loaders like CommonJS and AMD, which enables TypeScript to be used in environments like Node.js on the desktop and with libraries like require.js in the browser.  Both of these module systems provide the ability to provide an explicit value for the module.  For example, a ‘Client’ class may be set as the exported value from a module, allowing the ‘import’ to directly import the class.  TypeScript 0.9 now includes “export =” to support this use case

    // client.ts 
class Client {
constructor(public name: string, public description: string) { }
}
export = Client;

// app.ts
import MyClient = require('./client');
var myClient = new MyClient("Joe Smith", "My #1 client");

Enums

TypeScript 0.9 includes a finalized design for enums, offering a typed way to work with finite collections of constant numeric values.

    enum Color { red, blue, green }

var myColor = Color.red;
console.log(Color[myColor]);

Enums also allow converting to and from string representations, by indexing into the enum, as shown using Color[myColor] in the above example.

Declaration Merging

Using declaration merging in TypeScript 0.9, you can now grow the static-side of a class or expand a function value with new properties by following each with a module definition of the same name.  This makes it possible to express API patterns like nested classes, functions with static properties and more.

    function readInput(separator = readInput.defaultSeparator) {
// read input
}
module readInput {
export var defaultSeparator = ":";
}

TypeScript 0.9 Compiler

This release includes a significantly re-engineered compiler, which lays the foundation for great tooling scalability going forward, and provides a much higher fidelity implementation of the TypeScript language specification.

The new compiler addresses over 150 issues reported on CodePlex since the 0.8 release.  These include places where the compiler now catches potential errors more reliably, more accurate tools, and general improvements across the board. 

The new compiler has been designed to enable better incremental performance while editing code in IDEs (completion lists, error reporting, hover type information, etc.).  This is important to ensure that TypeScript IDEs can scale up to the 100k+ line of code codebases that we are already seeing be written in TypeScript today.  The 0.9 release marks the first big step with this new compiler architecture.  Already, 0.9 offers markedly improved editing performance for large codebases, and we expect this to continue to increase significantly as we further tune the new compiler. 

One temporary impact of these changes is that command line compiler compilation with 0.9 is somewhat slower than 0.8.  We expect to see significant improvements here in 0.9.1.

Summary

Check out TypeScript 0.9 today, watch the discussion video on Channel 9, and send us feedback at typescript.codeplex.com.

 

Leave a Comment
  • Please add 5 and 5 and type the answer here:
  • Post
  • Awesome! Can't wait to try it out!

  • Thank you for the updated docs! But please address the TODO: Finish* parts!

  • @Crwth - which TODO: Finish* parts are you referring to?

  • Awesome release, generics is a huge feature, will make it much easier to model existing libraries like Knockout. Congrats, guys!

  • Congrats guys! Can't wait to dig into it. We really appreciate all the hard work! I've noticed all the middle-of-the-night and weekend check-ins!

    @JonathanTurner Enums also seem to be allowed to contain arbitrary types now (including strings). I hope this was intentional as it's extremely useful.

  • One more thing- you guys need to get this blog added to the dev tools feed (blogs.msdn.com/.../developer-tools) on MSDN. I check up on that frequently and often miss these blog posts for a while because TypeScript is not included there.

  • Quite a milestone update. I guess time to start digging into TypeScript.

  • Haxe is still better. http://haxe.org/

  • Will typeScript let javascript become very very slow?

    Just like microsoft 12 years ago develop a good and complicated lanauage like c#, but also send developer a very very slow .net framework.

  • 1. Can you please upgrade Playground with v.9?

    2. Are you planning to release some documentation on TypeScript services API? At the moment one has to guess the meaning of methods and especially numerous small options, and it's quite hit and miss.

    Many thanks for your work!

  • @john, are you kidding. Do you even care about to know what is typescript.

    Why on earth people find c# slow? You don't know how to write a code does not mean a language slow or anything.

  • Great to hear that 0.9 is ready!

    I think the typescript blog is not yet listed on blogs.msdn.com/.../developer-tools

    It would be nice if you could change that.

  • The ES6 spec has moved away from lexical modules - which TypeScript uses.

    Will TypeScript 1.0 support ES6 modules directly.

  • What are the plans for ES6 let/const support. Wait until chakra and the other engines supports them directly.

    How about in TypeScript:

    var - for duck types

    let/const - for type inference

  • Could TypeScript use it's type info to support asm.js. Supporting 'int' and even SIMD style vector/matrix types - with a module pragma/annotation of some kind:

    @numeric module test { // Numeric subset - cannot access the DOM.  Compile to asm.js

        function area(a:int, b:int) => a * b;

    }

    let a = test.area(4,5);

    Basically 'numeric' modules would be for low-level machine type programming. Normal modules would be dynamic OO.

Page 1 of 3 (36 items) 123