InfoQ Homepage News TypeScript 1.5: Modules, Decorators, Sublime Text Plug-in and More

TypeScript 1.5: Modules, Decorators, Sublime Text Plug-in and More

Microsoft has released TypeScript 1.5 alpha incorporating a number of new features, including: modules, decorators, a plug-in for Sublime Text, for…of loops, ES6 Unicode, computed properties and let/const compilation to ES5.

One of the most expected features is modules, and TypeScript 1.5 has incorporated them as they are defined in ES 6, including the default export/import. The following snippet shows how to use modules:

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

// main.ts
import times from "math";

or importing all

// main.ts
import * as Math from "math";

While Microsoft is going to support the existing external modules, they encourage developers to “use the more capable ES6 module syntax.”

A new TypeScript feature available in preview form is Decorators, an ES7 proposal and a "strict superset of the capabilities of metadata annotations", according to Yehuda Katz, champion of the Decorators proposalThe following snippet is an example of using a decorator to memoize a getter/setter pair:

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

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

Microsoft has created a Sublime Text plug-in enabling developers to create, format and refactor TypeScript code with the respective editor. Both Sublime Text 2 and 3 are supported on Linux, OS X and Windows.

Other features added to TypeScript 1.5 are: for..of loops, ES6 Unicode, computed properties, and let/const compilation to ES5.

Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

• Incorrect Information

by Rob Eisenberg /

• Re: Incorrect Information

by Abel Avram /

• Incorrect Information

Your message is awaiting moderation. Thank you for participating in the discussion.

Google actually did not want to incorporate Decorators in AtScript. AtScript had a feature called "Annotations". Though the syntax is similar, these are two semantically different things entirely. Annotations was never an ECMA standard at all. It was never even proposed. Decorators was proposed as a standard. The spec is championed by Yehuda Katz of Ember. Some additional design work was done by Rob Eisenberg of Aurelia and then the TypeScript team did a ton of work to formalize the spec and create the first implementation. While this was going on, Angular still did not want to use Decorators and was trying to convince TypeScript to support their non-standard feature. They had to be convinced to drop their non-standard annotations implementations and support decorators....an actual ECMA spec.

Your story is backwards with respect to all this. Microsoft did not add the respective AtScript feature. Rather, Microsoft continued with their original vision of aligning with ECMA and then went to Angular and tried to convince them to drop their non-standards-based approach.

• Re: Incorrect Information

by Abel Avram /

Your message is awaiting moderation. Thank you for participating in the discussion.

After some more thought on this, I edited the paragraph to read: "A new TypeScript feature available in preview form is Decorators, an ES7 proposal and a "strict superset of the capabilities of metadata annotations", according to Yehuda Katz, champion of the Decorators proposal."
Thank you for pointing this out.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.