Typescript编译器忘记添加括号了吗?

Typescript编译器忘记添加括号了吗?,typescript,Typescript,我在编译这段特定代码时遇到了一个问题(这段代码来自Angular2项目) 公共重载记录(){ 让步骤=(this.timeInterval.max-this.timeInterval.min)/this.recordsChartSteps; 让数据=新数组(this.recordsChartSteps); 让标签=新数组(this.recordsChartSteps); 让doneCount=0; let done=new EventEmitter(); 完成。订阅(()=>{ 此.record

我在编译这段特定代码时遇到了一个问题(这段代码来自Angular2项目)

公共重载记录(){
让步骤=(this.timeInterval.max-this.timeInterval.min)/this.recordsChartSteps;
让数据=新数组(this.recordsChartSteps);
让标签=新数组(this.recordsChartSteps);
让doneCount=0;
let done=new EventEmitter();
完成。订阅(()=>{
此.recordsChartData[0]。数据=数据;
this.recordsChartLabels=标签;
});
如果(this.timeInterval.min==0)
this.data.getRecordCount(this.timeInterval.min,this.timeInterval.max).subscribe(count=>{
data[data.length-1]=计数;
标签[labels.length-1]=“总计”;
完成。发射();
});
else for(设i=0;i{
数据[i]=计数;
标签[i]=“De”+新日期(最小).toLocaleTimeString()+“a”+新日期(最大).toLocaleTimeString();
如果(++doneCount>=this.recordsChartSteps)done.emit();
}); 
}
}
使用typescript版本2.0.10(来自npm),这是我得到的输出

GlobalViewComponent.prototype.reloadRecords = function () {
    var _this = this;
    var step = (this.timeInterval.max - this.timeInterval.min) / this.recordsChartSteps;
    var data = new Array(this.recordsChartSteps);
    var labels = new Array(this.recordsChartSteps);
    var doneCount = 0;
    var done = new core_1.EventEmitter();
    done.subscribe(function () {
        _this.recordsChartData[0].data = data;
        _this.recordsChartLabels = labels;
    });
    if (this.timeInterval.min == 0)
        this.data.getRecordCount(this.timeInterval.min, this.timeInterval.max).subscribe(function (count) {
            data[data.length - 1] = count;
            labels[labels.length - 1] = "Total";
            done.emit();
        });
    else
        var _loop_1 = function(i) {
            var min = this_1.timeInterval.min + step * i;
            var max = min + step - 1;
            this_1.data.getRecordCount(min, max)
                .subscribe(function (count) {
                data[i] = count;
                labels[i] = "De " + new Date(min).toLocaleTimeString() + " à " + new Date(max).toLocaleTimeString();
                if (++doneCount >= _this.recordsChartSteps)
                    done.emit();
            });
        };
        var this_1 = this;
        for (var i = 0; i < this.recordsChartSteps; i++) {
            _loop_1(i);
        }
};
GlobalViewComponent.prototype.reloadRecords=函数(){
var_this=这个;
var step=(this.timeInterval.max-this.timeInterval.min)/this.recordsChartSteps;
var data=新数组(this.recordsChartSteps);
var labels=新数组(this.recordsChartSteps);
var doneCount=0;
var done=new core_1.EventEmitter();
完成。订阅(函数(){
_此.recordsChartData[0]。数据=数据;
_this.recordsChartLabels=标签;
});
如果(this.timeInterval.min==0)
this.data.getRecordCount(this.timeInterval.min,this.timeInterval.max).subscribe(函数(计数){
data[data.length-1]=计数;
标签[labels.length-1]=“总计”;
完成。发射();
});
其他的
var _loop_1=函数(i){
var min=此_1.timeInterval.min+步骤*i;
var最大值=最小值+步骤-1;
这是1.data.getRecordCount(最小值,最大值)
.订阅(功能(计数){
数据[i]=计数;
标签[i]=“De”+新日期(最小).toLocaleTimeString()+“a”+新日期(最大).toLocaleTimeString();
如果(++doneCount>=\u此.recordsChartSteps)
完成。发射();
});
};
var this_1=此;
对于(var i=0;i
这是有效的Javascript代码,但是编译器似乎没有为else块的内容添加必要的括号

我理解这很可能是因为我没有在我的Typescript代码中添加这些括号,因为else语句包含一个块(不需要括号,如果我错了,请纠正我)

但是,在Javascript中,else块(Typescript中的一个for循环)输出到多个语句

您甚至可以看到indendation,我认为在声明_loop_1变量的第一条指令之后的两条指令也应该包含在这个else块中是有意义的

显然,我可以通过在我的Typescript代码中添加括号来解决这个问题(据我所知,这可能是更好的做法)

是我的错误没有把这些括号,还是这是一个编译器的问题,我应该报告


注意:英语不是我的主要语言。

是的,这看起来像一个bug,你应该报告它。这里是一个快速简化的复制:

var test = false;
if (test) for (let i = 0; i < 10; i++) {
  let x = () => i;
}
var测试=false;
如果(测试)为(设i=0;i<10;i++){
设x=()=>i;
}


这段代码肯定什么都不做,如果你在我的本地Chrome浏览器中运行它,它就会这样做。如果您通过TypeScript运行它,但它会抛出“未捕获的TypeError:_loop_1不是函数”。伟大的发现

我认为您可以添加一个问题。:)非常感谢。我会报告的。
var test = false;
if (test) for (let i = 0; i < 10; i++) {
  let x = () => i;
}