@(at符号)在最新的TypeScript(可能是v1.5)示例中意味着什么? [英] What does the @ (at sign) mean in the latest TypeScript (presumably v1.5) example?

查看:314
本文介绍了@(at符号)在最新的TypeScript(可能是v1.5)示例中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在官方TypeScript中发布了一张非常有趣的图片。



因此描述了注释




  • AtScript注释语法只是放置注释的简写ES5中的相同信息。 ES5开发人员手动编写这些注释是合理的。甚至可以提供帮助程序库。

  • 注释只能放在函数上。


  • 放在类上的注释是放在类'构造函数上的注释。


  • 放置在字段上的注释将移动到构造函数。


  • 所有注释都转换为函数的属性。



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.

解决方案

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

这篇关于@(at符号)在最新的TypeScript(可能是v1.5)示例中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆