【发布时间】:2016-12-02 16:01:02
【问题描述】:
我使用aurelia-cli 和au new 命令生成了一个新的Aurelia 项目。
这是给我的app.ts:
export class App {
message = 'Hello World!';
}
我用 app.ts 从这个 tutorial 更新了我的 app.ts,如下所示:
export class App {
constructor() {
this.message = 'Hello World!';
this.firstName = "Animesh";
this.lastName = "Bulusu";
}
get fullName() {
return `${this.firstName} ${this.lastName}`;
}
}
我可以在刷新页面时看到预期的输出,但在错误控制台中出现这些错误。
“应用”类型上不存在属性“消息”。
类型“App”上不存在属性“lastName”。
“App”类型上不存在属性“lastName”。
如果我删除构造函数并将变量直接放在类中,这些错误就会消失。为什么会这样?如何消除这些错误?
【问题讨论】:
-
声明那些属性?例如:
private message : string -
我建议你阅读 Typescript 中的类。它会让你的概念更清晰。 typescriptlang.org/docs/handbook/classes.html
标签: javascript typescript visual-studio-code aurelia