javascript - Angular 2 属性注释不编译

标签 javascript typescript angular

下面的代码

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(它使用最新的 typescript 版本)

最佳答案

Unable to resolve signature of parameter decorator when called as an expression. Supplied parameters do not match any signature of call target.

谷歌搜索这个错误:https://github.com/Microsoft/TypeScript/issues/3661

从中你可以看到:

装饰函数形式参数目前不是 ES7 提案的一部分。

所以我怀疑 constructor(@Attribute('no-teaser') noTeaser)最新 TypeScript 中是故意不允许的(给出 ntypescripthttps://github.com/TypeStrong/ntypescript )。如果是这种情况,请将问题报告给 Microsoft/TypeScript。

Is it possible to tell atom-typescript which version of tsc to use?

不容易,因为旧版本的 TSC 可能与最新的 API 不兼容 ...但是有这个选项:https://github.com/TypeStrong/atom-typescript/blob/master/docs/faq.md#can-i-use-a-custom-typescript-compiler

关于javascript - Angular 2 属性注释不编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32538316/

相关文章:

javascript - html5 可拖动 - 任意放置位置?

javascript - php将pdf文件打印到指定的网络打印机而不打开对话框

javascript - three.js 3d 模型作为超链接

javascript - VS 代码中 Firebase 的代码完成?

typescript - 如何在 typescript 中输入生成器函数

css - 填充外部导入的 svg 文件

angular - 如何在 Angular 2 中将模态作为单独的组件制作?

Javascript 与 onclick 和 onmouseout 冲突

reactjs - 克隆元素 : Type has no properties in common with type Partial<P> & Attributes

angular - 自动将子组件数据更改发送到父组件