BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

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

Lire ce contenu en français

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

Adoption
Style

BT