There is a very interesting picture was posted in the official TypeScript blog.
I wonder what the @ (at sign) symbol is doing there since (as far as I know) it cannot be used in JavaScript identifiers.
There is a very interesting picture was posted in the official TypeScript blog.
I wonder what the @ (at sign) symbol is doing there since (as far as I know) it cannot be used in JavaScript identifiers.
Share Improve this question edited Oct 6, 2016 at 4:42 Chris Wijaya 1,2863 gold badges16 silver badges34 bronze badges asked Mar 6, 2015 at 19:49 Trident D'GaoTrident D'Gao 19.7k21 gold badges99 silver badges168 bronze badges 2- 2 i would read up on atscript. it is called an annotation. – Daniel A. White Commented Mar 6, 2015 at 19:51
- 8 In TypeScript, the "@" operator denotes a decorator (in the example above, a class decorator). You can learn more about decorators in the TypeScript docs. – sherb Commented Jun 28, 2016 at 20:31
1 Answer
Reset to default 20The big news this week is the merging of AtScript and TypeScript.
The following example from the AtScript documentation...
@Component()
class MyApp {
server:Server;
@Bind('name') name:string;
@Event('foo') fooFn:Function;
@Inject()
constructor(@parent server:Server) {}
greet():string {}
}
Compiles into the following JavaScript...
function MyApp() {}
MyApp.properties = {
'server': { is: Server },
'name': { is:string,
annotate: [new Bind('name']},
'fooFn': { is:Function,
annotate:[new Event('foo')]}
}
MyApp.annotate = [
new Component(),
new Inject()
];
MyApp.parameters = [
{is:Server, annotate:[parent]}
];
MyApp.prototype.greet = function() {}
MyApp.prototype.greet.returns = string;
AtScript was planned to be a layer on top of TypeScript (i.e. a super-set of a super-set) - but now the two projects are one.
Annotations are described thus:
- AtScript annotation syntax is just a shorthand of placing the same information in ES5. It would be reasonable for an ES5 developer to write these annotations manually. A helper library could even be provided.
Annotations can only be placed on functions.
An annotation placed on a class is an annotation placed on the class’ constructor function.
An annotation placed on a field gets moved to the constructor function.
All annotations are translated as properties on a function.