<p dir="auto"><strong>TypeScript Version: 1.8.10</strong></p>
<p dir="auto"><strong>Code</strong><br>
This is the file in the libary</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// File ../../lib/test.ts
/**
 * Created by ThomasP on 29.04.2016.
 */

export function test(): number {
    return Model.getNum();
}

export class Model {

    static getNum():  number {
        return 1;
    }
}"><pre class="notranslate"><span class="pl-c">// File ../../lib/test.ts</span>
<span class="pl-c">/**</span>
<span class="pl-c"> * Created by ThomasP on 29.04.2016.</span>
<span class="pl-c"> */</span>

<span class="pl-k">export</span> <span class="pl-k">function</span> <span class="pl-en">test</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">number</span> <span class="pl-kos">{</span>
    <span class="pl-k">return</span> <span class="pl-smi">Model</span><span class="pl-kos">.</span><span class="pl-en">getNum</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">export</span> <span class="pl-k">class</span> <span class="pl-smi">Model</span> <span class="pl-kos">{</span>

    <span class="pl-k">static</span> <span class="pl-en">getNum</span><span class="pl-kos">(</span><span class="pl-kos">)</span>:  <span class="pl-smi">number</span> <span class="pl-kos">{</span>
        <span class="pl-k">return</span> <span class="pl-c1">1</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">And this is the test spec for the libary file</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// File: test.Spec.ts
import {test} from &quot;../../lib/test&quot;;
/**
 * Created by ThomasP on 29.04.2016.
 */

describe( 'test', function () {

    it( 'should be able to get Model', function () {
        expect( test() ).toBe( 1 );
    });

});"><pre class="notranslate"><span class="pl-c">// File: test.Spec.ts</span>
<span class="pl-k">import</span> <span class="pl-kos">{</span><span class="pl-s1">test</span><span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">"../../lib/test"</span><span class="pl-kos">;</span>
<span class="pl-c">/**</span>
<span class="pl-c"> * Created by ThomasP on 29.04.2016.</span>
<span class="pl-c"> */</span>

<span class="pl-en">describe</span><span class="pl-kos">(</span> <span class="pl-s">'test'</span><span class="pl-kos">,</span> <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>

    <span class="pl-en">it</span><span class="pl-kos">(</span> <span class="pl-s">'should be able to get Model'</span><span class="pl-kos">,</span> <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-en">expect</span><span class="pl-kos">(</span> <span class="pl-en">test</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">toBe</span><span class="pl-kos">(</span> <span class="pl-c1">1</span> <span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">The actual compile target is es6 and the module system is system, see below</p>
<div class="highlight highlight-source-json notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  &quot;compilerOptions&quot;: {
    &quot;target&quot;: &quot;es6&quot;,
    &quot;module&quot;: &quot;system&quot;,
    &quot;moduleResolution&quot;: &quot;node&quot;,
    &quot;sourceMap&quot;: true,
    &quot;emitDecoratorMetadata&quot;: true,
    &quot;experimentalDecorators&quot;: true,
    &quot;removeComments&quot;: false,
    &quot;noImplicitAny&quot;: false
  },
  &quot;exclude&quot;: [
    &quot;node_modules&quot;
  ]
}"><pre class="notranslate">{
  <span class="pl-ent">"compilerOptions"</span>: {
    <span class="pl-ent">"target"</span>: <span class="pl-s"><span class="pl-pds">"</span>es6<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"module"</span>: <span class="pl-s"><span class="pl-pds">"</span>system<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"moduleResolution"</span>: <span class="pl-s"><span class="pl-pds">"</span>node<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"sourceMap"</span>: <span class="pl-c1">true</span>,
    <span class="pl-ent">"emitDecoratorMetadata"</span>: <span class="pl-c1">true</span>,
    <span class="pl-ent">"experimentalDecorators"</span>: <span class="pl-c1">true</span>,
    <span class="pl-ent">"removeComments"</span>: <span class="pl-c1">false</span>,
    <span class="pl-ent">"noImplicitAny"</span>: <span class="pl-c1">false</span>
  },
  <span class="pl-ent">"exclude"</span>: [
    <span class="pl-s"><span class="pl-pds">"</span>node_modules<span class="pl-pds">"</span></span>
  ]
}</pre></div>
<p dir="auto"><strong>Expected behavior:</strong><br>
The test should work and the method test should be able to call the static method on the class Model<br>
<strong>Actual behavior:</strong><br>
The class Model is not reachable for the method test. The compiled target looks like this. Model will be defined but is undefined. Creating the class Model in the local execute function will <strong>not</strong> set Model to the variable defined in the context.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="/**
 * Created by ThomasP on 29.04.2016.
 */
System.register([], function(exports_1, context_1) {
    &quot;use strict&quot;;
    var __moduleName = context_1 &amp;&amp; context_1.id;
    var Model;
    function test() {
        return Model.getNum();
    }
    exports_1(&quot;test&quot;, test);
    return {
        setters:[],
        execute: function() {
            class Model {
                static getNum() {
                    return 1;
                }
            }
            exports_1(&quot;Model&quot;, Model);
        }
    }
});
//# sourceMappingURL=test.js.map"><pre class="notranslate"><span class="pl-c">/**</span>
<span class="pl-c"> * Created by ThomasP on 29.04.2016.</span>
<span class="pl-c"> */</span>
<span class="pl-v">System</span><span class="pl-kos">.</span><span class="pl-en">register</span><span class="pl-kos">(</span><span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-s1">exports_1</span><span class="pl-kos">,</span> <span class="pl-s1">context_1</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-s">"use strict"</span><span class="pl-kos">;</span>
    <span class="pl-k">var</span> <span class="pl-s1">__moduleName</span> <span class="pl-c1">=</span> <span class="pl-s1">context_1</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">context_1</span><span class="pl-kos">.</span><span class="pl-c1">id</span><span class="pl-kos">;</span>
    <span class="pl-k">var</span> <span class="pl-v">Model</span><span class="pl-kos">;</span>
    <span class="pl-k">function</span> <span class="pl-en">test</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">return</span> <span class="pl-v">Model</span><span class="pl-kos">.</span><span class="pl-en">getNum</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
    <span class="pl-s1">exports_1</span><span class="pl-kos">(</span><span class="pl-s">"test"</span><span class="pl-kos">,</span> <span class="pl-s1">test</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">return</span> <span class="pl-kos">{</span>
        <span class="pl-c1">setters</span>:<span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
        <span class="pl-en">execute</span>: <span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-k">class</span> <span class="pl-v">Model</span> <span class="pl-kos">{</span>
                <span class="pl-k">static</span> <span class="pl-en">getNum</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
                    <span class="pl-k">return</span> <span class="pl-c1">1</span><span class="pl-kos">;</span>
                <span class="pl-kos">}</span>
            <span class="pl-kos">}</span>
            <span class="pl-s1">exports_1</span><span class="pl-kos">(</span><span class="pl-s">"Model"</span><span class="pl-kos">,</span> <span class="pl-v">Model</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-c">//# sourceMappingURL=test.js.map</span></pre></div>
<p dir="auto"><strong>Solution:</strong><br>
I think all defined classes must be set to the variables, which are defined in the upper context. Than the module will work as expected. I changed he output like above and now it will work fine. Another possible solution is to define a class not in the execute function, should be also work as expected.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="/**
 * Created by ThomasP on 29.04.2016.
 */
System.register([], function(exports_1, context_1) {
    &quot;use strict&quot;;
    var __moduleName = context_1 &amp;&amp; context_1.id;
    var Model;
    function test() {
        return Model.getNum();
    }
    exports_1(&quot;test&quot;, test);
    return {
        setters:[],
        execute: function() {
            Model = class Model {
                static getNum() {
                    return 1;
                }
            }
            exports_1(&quot;Model&quot;, Model);
        }
    }
});
//# sourceMappingURL=test.js.map"><pre class="notranslate"><span class="pl-c">/**</span>
<span class="pl-c"> * Created by ThomasP on 29.04.2016.</span>
<span class="pl-c"> */</span>
<span class="pl-v">System</span><span class="pl-kos">.</span><span class="pl-en">register</span><span class="pl-kos">(</span><span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-s1">exports_1</span><span class="pl-kos">,</span> <span class="pl-s1">context_1</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-s">"use strict"</span><span class="pl-kos">;</span>
    <span class="pl-k">var</span> <span class="pl-s1">__moduleName</span> <span class="pl-c1">=</span> <span class="pl-s1">context_1</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">context_1</span><span class="pl-kos">.</span><span class="pl-c1">id</span><span class="pl-kos">;</span>
    <span class="pl-k">var</span> <span class="pl-v">Model</span><span class="pl-kos">;</span>
    <span class="pl-k">function</span> <span class="pl-en">test</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">return</span> <span class="pl-v">Model</span><span class="pl-kos">.</span><span class="pl-en">getNum</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
    <span class="pl-s1">exports_1</span><span class="pl-kos">(</span><span class="pl-s">"test"</span><span class="pl-kos">,</span> <span class="pl-s1">test</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">return</span> <span class="pl-kos">{</span>
        <span class="pl-c1">setters</span>:<span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
        <span class="pl-en">execute</span>: <span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-v">Model</span> <span class="pl-c1">=</span> <span class="pl-k">class</span> <span class="pl-v">Model</span> <span class="pl-kos">{</span>
                <span class="pl-k">static</span> <span class="pl-en">getNum</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
                    <span class="pl-k">return</span> <span class="pl-c1">1</span><span class="pl-kos">;</span>
                <span class="pl-kos">}</span>
            <span class="pl-kos">}</span>
            <span class="pl-s1">exports_1</span><span class="pl-kos">(</span><span class="pl-s">"Model"</span><span class="pl-kos">,</span> <span class="pl-v">Model</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-c">//# sourceMappingURL=test.js.map</span></pre></div>
<p dir="auto">We have a large TypeScript project using different git repositories to separate work domains inside the project. We tend to create separate repositories for self-contained modules and use those modules in other repositories using git submodules. This helps tremendously to reduce clutter and distribute work.</p>
<p dir="auto">In our case some modules are used in many other repositories and those repositories are in turn used in other repositories. This sometimes leads to duplicate sources in projects using submodules which themselves depend on a common submodule. Assume the following example to clarify this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Project git
|-- A (git submodule)
|   |-- a.ts
|   |-- C (git submodule)
|       |-- c.ts
|-- B (git submodule)
|   |-- b.ts
|   |-- C (git submodule)
|       |-- c.ts
|-- app.ts

Submodule A git
|-- a.ts
    |-- C (git submodule)
        |-- c.ts

Submodule B git
|-- b.ts
    |-- C (git submodule)
        |-- c.ts

Submodule C git
|-- c.ts"><pre class="notranslate"><code class="notranslate">Project git
|-- A (git submodule)
|   |-- a.ts
|   |-- C (git submodule)
|       |-- c.ts
|-- B (git submodule)
|   |-- b.ts
|   |-- C (git submodule)
|       |-- c.ts
|-- app.ts

Submodule A git
|-- a.ts
    |-- C (git submodule)
        |-- c.ts

Submodule B git
|-- b.ts
    |-- C (git submodule)
        |-- c.ts

Submodule C git
|-- c.ts
</code></pre></div>
<p dir="auto">In this case submodule C is a self-contained repository used as submodule in repositories A and B which in turn are used as submodules in our main project git. This results in duplicate sources for <code class="notranslate">c.ts</code> in the main project which can sometimes lead to compiler errors along the lines of <code class="notranslate">Types have separate declarations bla bla</code>. See <a href="https://github.com/Microsoft/TypeScript/issues/5039#issuecomment-161264023" data-hovercard-type="issue" data-hovercard-url="/microsoft/TypeScript/issues/5039/hovercard">#5039</a> for an example (this feature request is a spin-off from the discussion in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="109143324" data-permission-text="Title is private" data-url="https://github.com/microsoft/TypeScript/issues/5039" data-hovercard-type="issue" data-hovercard-url="/microsoft/TypeScript/issues/5039/hovercard" href="https://github.com/microsoft/TypeScript/issues/5039">#5039</a> which proposes path mappings).</p>
<p dir="auto">This is because the TypeScript compiler treats the duplicate implementations of submodule C as separate implementations. Would it not be nice if the compiler detects those duplicate sources (by generating some sort of hash for each compiled source) and automatically maps subsequent sources to the first source already compiled? It would greatly improve the use of git submodules in TypeScript projects and prevents the formation of separate type declarations.</p>