繁体   English   中英

Angular 2 Attribute Annotation无法编译

[英]Angular 2 Attribute Annotation does not compile

以下代码

import {Attribute, Component, View} from 'angular2/angular2';

@Component({
  selector: 'card'
})
@View({
  templateUrl: "app/design/card/card.html",
  styleUrls: ["app/design/card/card.css"],
  directives: []
})
export class Card {
  constructor(@Attribute('no-teaser') noTeaser) {
    this.active=false
  }
}

给了我错误

Unable to resolve signature of parameter decorator when called as an expression. Supplied parameters do not match any signature of call target.
@Attribute('home')

将TypeScript转换为JavaScript时。

我正在使用Alpha 37,来自DefinitelyTyped的最新定义,我正在使用atom-typescript(使用最新的打字稿版本)

当作为表达式调用时,无法解析参数装饰器的签名。 提供的参数与呼叫目标的任何签名都不匹配。

谷歌搜索此错误结果: https//github.com/Microsoft/TypeScript/issues/3661

你可以看到:

Decorating function formal parameters is currently not part of the ES7 proposal.

所以我怀疑constructor(@Attribute('no-teaser') noTeaser)最新的 TypeScript中被故意禁止(给ntypescript一个去https://github.com/TypeStrong/ntypescript )。 如果是这种情况,请向Microsoft / TypeScript报告问题。

是否可以告诉atom-typescript使用哪个版本的tsc?

不容易,因为较旧版本的TSC可能与最新的API不兼容 ...但是有这个选项: https//github.com/TypeStrong/atom-typescript/blob/master/docs/faq.md#can -i使用-A-定制打字稿编译

这是如何在角度中定义属性注释的问题。 尝试创建自己的注释时,我遇到了同样的错误:

export function Attribute(name: string) {
    return function(a, b) {
        console.log(a);
        console.log(b);
    }
}

像你一样给出同样的错误,所以当我改为这个时:

export function Attribute(name: string) {
    return function(a, b, c) {
        console.log(a);
        console.log(b);
        console.log(c);
    }
}

错误消失了。 看起来您需要向角度项目提交问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM