升級到使用最新Typescript版本(2.2.1)的Ionic3後,我面臨着大問題。我有一個正常的Typescript類BoxList,它擴展了Array。所以這是正常的數組,其中還有一些我使用的自定義方法。我有一個名爲「allHit」的方法,它遍歷數組並返回布爾值。問題是,在Ionic2一切工作正常,但在升級之後,我不能再調用this.boxList.allHit
方法,因爲它引發了我的異常:Typescript對象擴展數組<BoxModel>不能再調用內部方法
-> 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);
}
有人知道這裏發生了什麼嗎?謝謝!
你可以添加功能到你的問題? –
嘿!我添加了全班。 – user2364292
你可以添加函數調用嗎? –