When exporting in TypeScript, it's important to differentiate between exporting a constant and exporting a type. For example, when you export a constant like this: let a = new Bar.Foo()
, the resulting variable a
will be of type Foo.
If you need to export both a type and a constant, you can do so by using namespaces:
namespace Bar
{
export const Qux = Foo;
export type Qux = Foo;
}
With this setup, you can then declare a variable as follows:
let a: Bar.Qux = new Bar.Qux();
In TypeScript, the compiler will infer whether you are referring to the type definition or the constant based on the context in which it is used.