我想將一個抽象類擴展到另一個類,但爲了更方便,我需要在另一個文件中有這個抽象類。不幸的是,它引發了我難以理解的運行時錯誤。從Typescript中的另一個模塊的繼承類
這工作:
abstract class Item{
constructor(){
console.log("I am an Item");
}
}
export class Folder extends Item{
constructor(){
super();
}
}
登錄:
I am an Item
這不:
module MyModule{
export abstract class Item{
constructor(){
console.log("I am an Item");
}
}
}
export class Folder extends MyModule.Item{
constructor(){
super();
}
}
編譯,但拋出:
Uncaught TypeError: Cannot read property 'prototype' of undefined
有誰知道發生了什麼事?
問題似乎來自出口抽象類。我剛發現的一個解決方案是聲明一個var,它將指向這個抽象類: export var ItemClass = Item; then: export class Folder extends MyModule.ItemClass; 它看起來像一個有效的解決方法嗎? – Kromah