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 3 and 6 and type the answer here:
  • Post
  • @oleg - the playground should be using 0.9 now.  You may have to clear out your browser cache to see the update.  We may release more information on the language service API once it's stabilized.

    @kc - there's some discussion around ES6 modules here: typescript.codeplex.com/.../446695

    We'll likely target more ES6 features after the 1.0.  

  • Is it me or is the download link on the download page missing for Typescript 0.9. There is a link for the release notes, but nothing for the actual download. I managed to work it out from the others...

  • Nice to see finished 0.9 with generics.

    There are small problems:

    - formatting does not work (ctrk+k, ctrl+d)

    - function code folded below function declaration. Please, revert back where code if folding in the same line as function declaration

    - while debigging, active line (yellow background) and breakpoint line (red background), colored background does not cover whole code, last character is missed

    Please add async as fast as possible. There is lot of async code with DOM events, server request/response and background workers. Asynchronous features are in extreme demand.

  • Congrats, but Typescript  still have all javascript flaws (scopes) - i want to stay sane and will stick to   dartlang www.dartlang.org

  • So Awesome team! Generics are a game changer for me.  So stoked to install today!

  • I don't know, why is typescript neccessary, instead of a good C# to javascript compiler.

  • @LCoder - TypeScript is aimed at developers who want modern abstractions, type-checking, tooling, and also good performance.  If you'd rather use C#, and don't mind the performance loss from using a language so different from JavaScript, there are projects like Script# (http://scriptsharp.com/) that will compile C# to JavaScript.

  • Has anybody else a noticeable slowdown of the compiling using Visual Studio 2012 and typescript 0.9?

    For me it feels sometimes double or more slower than 0.8.3.1. And mostly I have to press the CTRL+S twice, before I see the result in the preview window.

  • @webdev - There is a slowdown in the compilation speeds (we mentioned it in the blog towards the bottom) that came up when we rewrote the compiler and language service for generics and better interactive performance.  We're working to improve this for 0.9.1 release.

  • When will we see something like this hit SharePoint and the new "App Model"?

  • fyi i am having a lot of troubles with AMD modules:

    1) i found /// <amd-dependency path="just/referencingthis/forpackaging" /> which helps, you should better document this feature.

    2) in visual studio, the "export = xxx" functionality does not play well with intelisence.  for example, i want to be able to use jquery with a d.ts file as such:    import $ = module("jquery");  i can't do that today.

    not amd related problems:

    1) non-ascii characters in comments crash the compiler with no helpful hints.

    2) compile speeds need to be improved to something like 0.8.x level of perf

  • I've seen some serious stability issues with the latest 0.9 release.  I installed over top of a previous version.  The install required a reboot.  After rebooting the first time I tried to build Visual Studio hung and TSC.exe was hung up.  I rebooted again and later while updating a .ts file visual studio hung and then my entire computer hung and I had to do a hard reboot.  I hope there is more stability to follow -- glad to see significant progress in the spec but need a stable compiler.

  • @Jason - you would need to use a version of jquery that could be loaded as an external module.  I believe that the .d.ts that ships with the samples doesn't have that capability, so you'd need to add it.  We're aware of the character encoding and compile time issues and we're looking into them.

    @kingdango - upgrading from 0.8 to 0.9 should automatically remove 0.8 for you (unless you made manual changes).  If this doesn't work, you could try uninstalling, manually removing the "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TypeScript" if it still exists, and reinstalling.  This should get you close to a vanilla install.  If this doesn't fix the issue, definitely let us know via the bug tracker (typescript.codeplex.com/.../Create)

  • i have the same problems as @kingdango  (It's not about upgrading, it's just about 0.9.0 stability)

    I ended up uninstalling 0.9 and going back to 0.8.3.1.   because of the quirks.  much happier with it, but of course no generics.

    ---

    on another subject,

    is typescript in the VS 2013 preview?  or will the vs 2012 plugin work with the vs2013 preview?

  • @jason for the problem with the non-ascii characters:

    save the .ts files in visual studio with a unicode encoding.

    Unicode (UTF-8 with signature) worked for me.

Page 2 of 3 (36 items) 123