I have downloaded the type definition of a module, let\'s say ModuleA, from @types/module-a
.
The module-a.d.ts file lo
I found that I could combine export =
syntax with namespace
to export types from the interface. export =
is necessary (as far as I understand) to indicate that an external module uses CommonJS-style exports
rather than ES6 exports. If you try to both use export =
and export
in the same module, you will receive the following error:
TS2309: An export assignment cannot be used in a module with other exported elements.
However, if you declare a declare a namespace with the same name as the variable used in the exports =
expression, you can place types inside of that namespace, making them accessible to consuming modules.
Here is an example of a module type definition using this technique:
declare module 'some-module' {
namespace SomeClass {
export interface IMyInterface {
x:string;
};
}
class SomeClass {
constructor(p:SomeClass.IMyInterface);
}
export = SomeClass;
}