I have a typescript project with a module splitted into multiple files. There is a class with the same name as this module to get nested classes via declaration merging, but the compiler throws errors:
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'.
file 'Foo.ts'
class Foo {
constructor() {
}
}
file 'Bar.ts'
module Foo {
export class Bar {
constructor() {
}
}
}
I'm compiling with tsc Foo.ts Bar.ts --declaration --out foo.js
My main Problem is, that I want to be able to use var bar = new Bar();
in my Foo-Class, which declaration-merging should provide in my mind (the language specification didn't really help me here). Right now I have to use var bar = new Foo.Bar();
, which is very annoying.
Am I doing something wrong or is this a compiler bug?
Btw, --declaration
doesn't seem to work, hope this is caused by those errors.