我正在使用commonJS模块创建一个库,我想在" lib"中定义自己模块中的类。目录然后有一个" main"从" lib"中的模块导入和导出类的模块。目录。我希望库的使用者能够扩展导出的类,但是typescript编译器似乎并不支持这一点。下面的代码是使用内部模块的简化repro。编译器为类BC
发出错误。有解决方法吗?
module A {
export class C {
}
}
module B {
export var C = A.C;
}
// this compiles
class AC extends A.C { }
// and this compiles
var bc = new B.C();
// this does not compile.
// compiler error: TS2305 Module 'B' has no exported member 'C'
class BC extends B.C {
}
答案 0 :(得分:4)
您需要将A.C
带入类型声明空间(import
关键字)而不是变量声明空间({{1} }关键字)。
var