BT
x Share your thoughts on trends and content!

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

by Abel Avram on Apr 03, 2015 |

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 {add, subtract} from "math";
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.

Rate this Article

Relevance
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.

Tell us what you think

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

Email me replies to any of my messages in this thread

Incorrect Information by Rob Eisenberg

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

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

Email me replies to any of my messages in this thread

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

Email me replies to any of my messages in this thread

2 Discuss
General Feedback
Bugs
Advertising
Editorial
Marketing
InfoQ.com and all content copyright © 2006-2016 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT

We notice you're using an ad blocker

We understand why you use ad blockers. However to keep InfoQ free we need your support. InfoQ will not provide your data to third parties without individual opt-in consent. We only work with advertisers relevant to our readers. Please consider whitelisting us.