<p dir="auto">There's a problem with the ES6 generated code when using inner classes. The code:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// Bug.ts
module Stuff {
    export class Foo {
        constructor (message: string) {
            this.Message = &quot;Hello, &quot; + message
        }
        Message = &quot;&quot;
    }
    export module Foo {
        export class Bar {
        }
    }
}
var foo = new Stuff.Foo(&quot;World&quot;)
console.log(foo.Message)"><pre class="notranslate"><span class="pl-c">// Bug.ts</span>
<span class="pl-smi">module</span> <span class="pl-v">Stuff</span> <span class="pl-kos">{</span>
    <span class="pl-k">export</span> <span class="pl-k">class</span> <span class="pl-v">Foo</span> <span class="pl-kos">{</span>
        <span class="pl-en">constructor</span> <span class="pl-kos">(</span><span class="pl-s1">message</span>: <span class="pl-s1">string</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">Message</span> <span class="pl-c1">=</span> <span class="pl-s">"Hello, "</span> <span class="pl-c1">+</span> <span class="pl-s1">message</span>
        <span class="pl-kos">}</span>
        <span class="pl-c1">Message</span> <span class="pl-c1">=</span> <span class="pl-s">""</span>
    <span class="pl-kos">}</span>
    <span class="pl-k">export</span> <span class="pl-smi">module</span> <span class="pl-v">Foo</span> <span class="pl-kos">{</span>
        <span class="pl-s1">export</span> <span class="pl-s1">class</span> <span class="pl-v">Bar</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">var</span> <span class="pl-s1">foo</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">Stuff</span><span class="pl-kos">.</span><span class="pl-c1">Foo</span><span class="pl-kos">(</span><span class="pl-s">"World"</span><span class="pl-kos">)</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">foo</span><span class="pl-kos">.</span><span class="pl-c1">Message</span><span class="pl-kos">)</span></pre></div>
<p dir="auto">compiled with <code class="notranslate">tsc -t ES6 Bug.ts</code> and then by <code class="notranslate">babel --no-highlight-code Bug.js</code> produces error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TypeError: Bug.js: Line 10: Duplicate declaration &quot;Foo&quot;
   8 |     }
   9 |     Stuff.Foo = Foo;
&gt; 10 |     var Foo;
     |         ^
  11 |     (function (Foo) {
  12 |         class Bar {
  13 |         }"><pre class="notranslate"><code class="notranslate">TypeError: Bug.js: Line 10: Duplicate declaration "Foo"
   8 |     }
   9 |     Stuff.Foo = Foo;
&gt; 10 |     var Foo;
     |         ^
  11 |     (function (Foo) {
  12 |         class Bar {
  13 |         }
</code></pre></div>
<p dir="auto">Closely related to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="63503889" data-permission-text="Title is private" data-url="https://github.com/microsoft/TypeScript/issues/2457" data-hovercard-type="issue" data-hovercard-url="/microsoft/TypeScript/issues/2457/hovercard" href="https://github.com/microsoft/TypeScript/issues/2457">#2457</a> and also in reference to <a class="commit-link" href="https://github.com/microsoft/TypeScript/commit/bd4d7fc9eedfb905313b173e284eddf95350e7dc#commitcomment-10328068"><tt>bd4d7fc</tt>#commitcomment-10328068</a></p>
<p dir="auto">A class merging with a module will not work in ES6, because you will end up redeclaring a class and a var (the var is what we emit for the module) in the same scope, which will cause a runtime error. So a class merging with a module needs to be renamed in a similar way as <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="63503889" data-permission-text="Title is private" data-url="https://github.com/microsoft/TypeScript/issues/2457" data-hovercard-type="issue" data-hovercard-url="/microsoft/TypeScript/issues/2457/hovercard" href="https://github.com/microsoft/TypeScript/issues/2457">#2457</a>, except as a var instead of a let.</p>