【发布时间】:2014-08-28 07:11:54
【问题描述】:
我无法在使用 typescript 1.0 生成的 CommonJS 模块之间进行继承(tscis run using --module commonjs)
当两个类继承同一个基类,“通过”基类相互调用时,这会失败。
似乎是第一个类导入了基类,它导入了第二个类,第二个类也导入了基类,但最后一个基类导入失败。
下面提供了一个说明此行为的示例。
Typescript 或 CommonJS 规范中是否有任何内容阻止我这样做,或者这是一个错误?
=== 示例 ===
这个迷人的软件因运行Lower.test.ts 而失败。它试图实现的只是将一个单词加载到Lower 中,使其保持小写,然后使用从Base 类继承的toUpper() 方法,使用Upper 类将其转换为大写(这也是继承Base)
Lower.test.ts
import Lower = require('./Lower')
console.log(new Lower('smallcaps').toUpper())
Base.ts
import Upper = require('./Upper')
class Base {
word: string
toUpper(): string {
return new Upper(this.word).word
}
}
export = Base
Upper.ts
import Base = require('./Base')
class Upper extends Base {
constructor(word:string) {
super()
this.word = word.toUpperCase()
}
}
export = Upper
Lower.ts
import Base = require('./Base')
class Lower extends Base {
constructor(word:string) {
super()
this.word = word.toLowerCase()
}
}
export = Lower
【问题讨论】:
标签: inheritance typescript commonjs