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 2 and 1 and type the answer here:
  • Post
  • @Jason - the plugin should work with the VS2013 preview.  If it doesn't please help us out by filing a bug on what doesn't work for you.

    What kind of instability were you seeing?  We're looking at possibly putting out a hotfix release to address some of the blocking issues people have hit, and I'd like to hear what you saw.

  • i moved back to 0.8.3.1 a week ago to avoid the issues, but i'll give 0.9.0.1 a try and list out the issues i'm still seeing.

  • So far my preferred language.

    if only it could fix JS for loops on dictionary/arrays complexities.

  • Building an AMD module, is there a way to specify requiresjs dependencies that are then automatically provided in the constructor?

  • @Chris1024 - When you use imports, you're setting up the require.js dependencies.  Is that what you mean?  

  • I'm not getting intellisense for the module when using Declaration Merging in a declaration file (*.d.ts). Is that a bug?

Page 3 of 3 (36 items) 123