April 30th, 2015

Announcing TypeScript 1.5 Beta

We have continued work on the TypeScript 1.5 release, and today we are one step closer.  You can now try out the TypeScript 1.5 beta as a download for VS 2015 RC, VS 2013, npm, or as source.The beta represents further progress to the final 1.5 release, with many bugfixes, support for a new metadata API that works with decorators, and updates to bring lib.d.ts up-to-date.

Decorator Metadata

TypeScript 1.5 beta introduces the new metadata API for working with decorators, allowing you to add and read metadata on declarations.  You can see how this works in the example below.

First, you need to install the polyfill for the new metadata API.  We’ve made this available on NPM:

> npm install reflect-metadata

Next, you can use this metadata as in the example below:

///<reference path=”node_modulesreflect-metadatareflect-metadata.d.ts”/>

import “reflect-metadata”;

function MyClassDecorator(value: string) {
  return function (target: Function) {
      Reflect.defineMetadata(“MyClassDecorator”, value, target);
  }
}

@MyClassDecorator(“my metadata”)
class MyClass { }

var myClass = new MyClass();
let value: string = Reflect.getMetadata(“MyClassDecorator”, myClass.constructor);
console.log(value); // outputs “my metadata”

You can compile this example using:

> tsc myFile.ts –module commonjs –target ES5

We’ve also added a new commandline option that will allow you to look at the types being passed into your decorators.  

> tsc myFile.ts –module commonjs –target ES5  –emitDecoratorMetadata

This is a being developed to help support the metadata needs of rich libraries, like the upcoming Angular 2 and Aurelia releases, which can use the metadata to automatically set up features like dependency injection.

Looking Ahead

Your feedback is important to us.  As we close in on completing the 1.5 release, your feedback will be crucial to helping us make sure the new features are at the highest quality they can be.  We’d love to hear from you.

Category
TypeScript

0 comments

Discussion are closed.