【发布时间】:2013-12-16 15:39:35
【问题描述】:
我有一个打字稿项目,其中一个模块被拆分为多个文件。有一个与该模块同名的类通过声明合并获取嵌套类,但编译器抛出错误:
Bar.ts(1,1): error TS2188: Module 'Foo' cannot merge with previous declaration of 'Foo' in a different file 'path/to/my/file/Foo.ts'.
文件'Foo.ts'
class Foo {
constructor() {
}
}
文件'Bar.ts'
module Foo {
export class Bar {
constructor() {
}
}
}
我正在使用tsc Foo.ts Bar.ts --declaration --out foo.js进行编译
我的主要问题是,我希望能够在我的 Foo 类中使用 var bar = new Bar();,声明合并应该在我的脑海中提供(语言规范在这里并没有真正帮助我)。现在我必须使用var bar = new Foo.Bar();,这很烦人。
是我做错了什么还是编译器错误?
顺便说一句,--declaration 似乎不起作用,希望这是由这些错误引起的。
【问题讨论】:
标签: typescript