Announcing TypeScript 1.5 Alpha

Luke Hoban [MS]

Today we’re announcing TypeScript 1.5 Alpha, the first preview of the TypeScript 1.5 release.  This release shows off many of the features that will be in the final TypeScript 1.5 release.  In the alpha release, you’ll be able to use three new capabilities of the TypeScript tools: a richer ES6 experience, decorators, and a new Sublime Text plugin.

You can try this alpha out today by installing the new compiler available on npm.

Richer ES6 experience

In TypeScript 1.5, we’re adding a number of new ES6 features.  These features work together with the TypeScript type system to give you helpful tooling when working with the new ES6 code patterns.

Modules

The module syntax of ES6 is a powerful way of working with modules.  You can interact with modules by importing whole modules or by working with individual exports directly.

import * as Math from “my/math”;
import { add, subtract } from “my/math”;

ES6 also supports a range of functionality in specifying exports.  You can export declarations, such as classes or functions.  You can also export a ‘default’ to import the module directly.  For example:

// math.ts

export function add(x, y) { return x + y }
export function subtract(x, y) { return x – y }
export default function multiply(x, y) { return x * y }

// myFile.ts

import {add, subtract} from “math”;
import times from “math”;
var result = times(add(2, 3), subtract(5, 3));

If you’ve been using TypeScript, you may notice that this is similar to TypeScript external modules.  This is no accident.  When we created external modules for TypeScript, we were working on the same problems.  The ES6 design takes the capabilities even further, showing a powerful, mature design.  We will continue to support external modules, but we will begin encouraging developers to use the more capable ES6 module syntax.

Destructuring

Destructuring is a handy new feature that comes as part of our ES6 support.  With it, you can pull apart, or destructure, objects and arrays.

var [x, y] = [10, 20];
[x, y] = [y, x];  // a simple swap

You can also use destructuring to handle function parameters:

var myClient = {name: “Bob”, height: 6};
function greetClient({name, height: howTall}) {
 
console.log(“Hello, “ + name + “, who is “ + howTall + ” feet tall.”);
}
greetClient(myClient); 

In the above, greetClient takes in a single object that has a name and height property. Using the ‘height: howTall’ syntax, we can rename the height property to howTall inside of greetClient.

And more

We’ve also added for-of support for better iteration, let/const compiling to ES5, unicode support, an ES6 output mode, and better support for computed properties.

Decorators

We’ve also worked with the Angular, Ember, and Aurelia (from the makers of Durandal) teams on a decorator proposal for ES7, which we’re previewing in TypeScript 1.5 Alpha.  Decorators allow you to create a clean separation of concerns.  In this example, we see how the @memoize decorator could be used to note that a getter/setter pair can be memoized:

class Person {
 
@memoize
 
get name() { return `${this.first} ${this.last}` }

  set name(val) {
    let [first, last] = val.split(‘ ‘);
   
this.first = first;
   
this.last = last;
 
}
}

Developers will be able to write new decorators and mix-and-match them to work with the type system.

Sublime Text plugin

Along with TypeScript 1.5 Alpha, we’re also releasing a preview of the Sublime Text plugin for TypeScript to enable more developers to get editor support when authoring TypeScript.  This plugin works with both Sublime Text 2 and Sublime Text 3 and shows some of what is possible with the TypeScript type system. Sublime Text and the TypeScript plugin are available for OSX, Linux, and Windows.


TypeScript commands available in Sublime Text

The Sublime Text plugin allows you to easily navigate, refactor, format, and investigate TypeScript code.  Those who tried the Sublime plugin that came with the ng-conf demo may also notice that this updated plugin is snappier, especially with larger files.

We’re excited to hear your feedback.  If you’d like to leave a comment, you can fill out an issue on the issue tracker.  Also, feel free to jump in and send us your pull requests to help make the Sublime plugin even better.

What’s next

This alpha release shows what will be possible in TypeScript 1.5 when it’s released, and we want to hear from you.  We’re working hard on TypeScript 1.5, and you can help us make it a strong release by trying it out and sending us any issues you find.

0 comments

Discussion is closed.

Feedback usabilla icon