mixing "declare" and "export" in same typescript file
<ul>
<li>I have a typescript based project</li>
<li>When I build this typescript project I do get a single bundle.js file which I can then import anywhere using <code>&lt;script src=&quot;bundle.js&quot;&gt;&lt;/script&gt;</code></li>
<li>I am importing my bundled typescript code within an environment which declares some global variables. Let's call one &quot;AGlobal&quot;</li>
<li>Within my typescript code, to avoid having compilation errors, I made a file aside we can call declare.ts as follow:</li>
</ul>
<h1>declare.ts</h1>
<pre><code>declare var AGlobal:IAGlobal;
interface IAGlobal
{
// the aNumber argument can only be 0 or 1
aFunction(aNumber:number):void;
}
</code></pre>
<p>In this way, from any ts file I can simply access the tool as follow:</p>
<h1>aFile.ts</h1>
<pre><code>import &quot;/path/to/declare&quot;
AGlobal.aFunction(42);
</code></pre>
<p>And everything will be fine.</p>
<hr />
<p>Now I am having the following problem, the &quot;AGlobal&quot; is actually making use of enum, in which case I should have to refactor declare.ts as:</p>
<h1>declare.ts</h1>
<pre><code>declare var AGlobal:IAGlobal;
declare enum AState
{
ON = 1,
OFF= 0,
}
interface IAGlobal
{
aFunction(aNumber:AState):void;
}
</code></pre>
<p>Which I then would like to be able to use within aFile.ts as follow:</p>
<h1>aFile.ts</h1>
<pre><code>import &quot;/path/to/declare&quot;
AGlobal.aFunction(AState.ON);
</code></pre>
<p>The code above is not generating any error BUT when I do compile it, I realised the <code>AState</code> enum is never added to the code and therefore I get a undefined error when trying to use <code>AState</code></p>
<p>I therefore thought to export the enum using &quot;export enum AState&quot; but then this will break the flat import of the whole file i.e. one export will break the flat import of the whole file (as ts then consider the file to be a module)</p>
<p>How could I then export or use this enum from my aFile.ts tile ?</p>