我在扩展项目时遇到问题,我得到:
未捕获的类型错误:无法读取未定义的属性“原型”
从我读过的内容来看,项目需要以特定的顺序定义,所以这就是我正在做的,因为看起来它们的顺序是正确的。
这不会发生在编译时,而是在浏览器运行时发生。我正在使用 browserify 和 tsify 将这些文件编译成一个文件。
这是我的入口点 main.ts :
import GameSmartWeb from './GameSmartWeb';
window.gs = new GameSmartWeb();
然后它调用这个引用 GUI 类的文件 GameSmartWeb.ts :
import GUI from './apis/GUI';
export default class GameSmartWeb {
public get gui(): GUI { return new GUI(); }
}
然后 GUI 类 apis/GUI.ts 看起来有点像这样:
export default class GUI extends GameSmartWeb {
public get rewards(): Rewards { return new Rewards(); }
}
class Rewards extends GUI {
// More methods
}
在浏览器中查看时,它说错误在这里:
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); // The error is on this line
};
var GUI = (function (_super) {
__extends(GUI, _super); // This is the call to the function
// more auto generated code
});
原文由 Get Off My Lawn 发布,翻译遵循 CC BY-SA 4.0 许可协议
这件事今天发生在我身上,尽管它似乎与你的原因不同。无论如何,我正在为将来来到这里的其他人写一个答案。
我的文件设置如下:
项目.ts :
index.ts (为了能够顺利引用):
其他.item.ts :
这导致了我的错误:
将 other.item.ts 更改为以下内容后,它起作用了: