【发布时间】:2020-08-04 15:05:06
【问题描述】:
我正在尝试在我正在开发的 Angular 网页中的 TypeScript 程序中执行一些 if/else 语句。这是一个可重现的案例:
export class AppComponent {
x: number = 0;
output: number = 0;
if (this.x < 0.5){
this.output = 1;
}
else if ((this.x >= 0.5) && (this.x < 1.0)){
this.output = 2;
}
else {
this.output = 3;
}
}
在我看来,这与我读过的关于 TypeScript 语法的教程相匹配,但显然有问题。
在 Visual Studio Code 编辑器中,它显示:
- 重复标识符“(缺失)”.ts(2300)
- 预期标识符.ts(1003)
- 参数 '(Missing)' 隐式具有 'any' 类型,但可以从 usage.ts(7044) 推断出更好的类型
而且,当我运行代码时,调试控制台会显示:
[WDS] Errors while compiling. Reload prevented.
(webpack)-dev-server/client:162
app.component.ts(10,11): error TS1005: ',' expected.
app.component.ts(10,22): error TS1005: ',' expected.
app.component.ts(10,24): error TS1003: Identifier expected.
app.component.ts(13,3): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
【问题讨论】:
标签: angular typescript