Annotations

Topics: General, Language Specification
Jun 22, 2013 at 9:13 AM
Edited Jun 23, 2013 at 10:00 PM
It is often necessary to annotate a class, a class property, or methods, in Javascript you generally do it like this :
function myAnnotation(type, property) {
// do something
}

function MyClass() {
}

myAnnotation(MyClass,'myProperty');

This often leads in bugs when you misspell 'myProperty'.
In typescript you already define property in the class declaration, it could create a way to have a more concise syntax, and eliminates such bug to have a mechanism like this one :
function myAnnotation(type, property) {
}

class MyClass {
    @myAnnotation;
    myProperty:string;
}
Coordinator
Jun 24, 2013 at 4:56 PM
There have been some experiments in this real under the 'decorators' fork (https://typescript.codeplex.com/SourceControl/network/forks/rbuckton/Decorators). You should feel free to try out the branch and give the author feedback. He does a lot of language experiments, and they're fun to hear about.

There are some nice advantages to the decorators, and we're just beginning to explore them.