Typescript 对象扩展了 Array<BoxModel> 无法再调用内部方法

Typescript object extends the Array<BoxModel> can not call the inside methods anymore

升级到使用最新 Typescript 版本 (2.2.1) 的 Ionic3 后,我遇到了一个大问题。我有一个扩展数组的普通 Typescript class BoxList。所以它是普通数组,我使用了一些额外的自定义方法。我有一个名为 "allHit" 的方法,它循环遍历数组和 returns 布尔值。问题是,在 Ionic2 中一切正常,但升级后,我不能再调用 this.boxList.allHit 方法,因为它会抛出异常:

-> main.js:1 ERROR TypeError: this.boxList.allHit is not a function(…)

代码:

import {BoxModel} from "./BoxModel";
export class BoxList extends Array<BoxModel> {

    constructor() {
        super();
    }

    public allHit(boxTarget: BoxModel) : boolean {
        return this.findIndex(box => box.doesMatch(boxTarget) && !box.isHit) === -1;
    }

    public findUntouchedBox() : BoxModel {
        return this.find(box => !box.isHit);
    }
}

以及从其他对象调用 allHit 方法:

public allBoxesAreHit() : boolean {
    return this.boxList.allHit(this.targetBox);
}

有人知道这里发生了什么吗?谢谢!

根据打字稿 2.1 breaking changes:

As part of substituting the value of this with the value returned by a super(...) call, subclassing Error, Array, and others may no longer work as expected. This is due to the fact that constructor functions for Error, Array, and the like use ECMAScript 6's new.target to adjust the prototype chain; however, there is no way to ensure a value for new.target when invoking a constructor in ECMAScript 5.

尝试他们的建议并设置:

constructor() { 
   super(); 
  Object.setPrototypeOf(this, BoxList.prototype); 
}

在构造函数中。