I have a class in a module.
module Foo {
export class Bar {
}
/* Some more interfaces and classes to be used only in this module */
}
var bar = new Foo.Bar();
This class is for a library, and I don't want other users to write Foo.Bar but just Bar to use my Bar class:
var bar = new Bar();
I can do this by defining a new variable Bar.
var Bar = Foo.Bar;
var bar = new Bar();
However, now I have a problem. I cannot use the Bar as a TypeScript type identifier.
function something(bar: Bar) { // Compiler: Could not find symbol 'Bar'.
}
I can also solve this problem by defining a new class that extends Foo.Bar.
class Bar extends Foo.Bar {
}
var bar = new Bar();
function something(bar: Bar) {
}
However, the resulting Bar class is not exactly same with Foo.Bar, as Bar === Foo.Bar and Bar.prototype === Foo.Bar.prototype both returns false.
I tried to find a method using TypeScript module feature such as import and require, but it seems I cannot do this with them. Is there any good method to expose my Bar class to global?