<h3 dir="auto">The bug</h3>
<p dir="auto">Let's say I have these two files</p>
<h4 dir="auto">foo.ts</h4>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="export default class Foo { }"><pre class="notranslate"><span class="pl-k">export</span> <span class="pl-k">default</span> <span class="pl-k">class</span> <span class="pl-v">Foo</span> <span class="pl-kos">{</span> <span class="pl-kos">}</span></pre></div>
<h4 dir="auto">bar.ts</h4>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import Foo from './foo';
let foo = new Foo();"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-v">Foo</span> <span class="pl-k">from</span> <span class="pl-s">'./foo'</span><span class="pl-kos">;</span>
<span class="pl-k">let</span> <span class="pl-s1">foo</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">Foo</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">If I compile these files with</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="tsc -t es6 -m commonjs foo.ts bar.ts"><pre class="notranslate"><code class="notranslate">tsc -t es6 -m commonjs foo.ts bar.ts
</code></pre></div>
<p dir="auto">I get this output</p>
<h4 dir="auto">foo.js</h4>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class Foo {}
exports.Foo = Foo;"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-v">Foo</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>
<span class="pl-s1">exports</span><span class="pl-kos">.</span><span class="pl-c1">Foo</span> <span class="pl-c1">=</span> <span class="pl-v">Foo</span><span class="pl-kos">;</span></pre></div>
<h4 dir="auto">bar.js</h4>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var foo_1 = require('./foo');
let foo = new foo_1.default();"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">foo_1</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'./foo'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">let</span> <span class="pl-s1">foo</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-s1">foo_1</span><span class="pl-kos">.</span><span class="pl-c1">default</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Obviously this code will not work.</p>
<h3 dir="auto">Solutions</h3>
<ol dir="auto">
<li>converting module type to <code class="notranslate">ES6</code>, this seems to be the definite solution</li>
<li>converting imports to <code class="notranslate">import * as Foo from './foo'</code> this fixes the produced code but show this error during compile</li>
</ol>
<blockquote>
<p dir="auto">bar.ts(3,11): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.</p>
</blockquote>
<h3 dir="auto">Confusion</h3>
<p dir="auto">Above code works without any workaround when targetting <code class="notranslate">ES5</code>. Is this the intended behavior? If so, shouldn't this be documented somewhere? Also instead of producing a code that does not work, maybe it should just say</p>
<blockquote>
<p dir="auto">commonjs modules cannot be used when targeting ES6</p>
</blockquote>
<p dir="auto">Sorry if this was already reported or was already documented.</p>
<p dir="auto">Using typescript@next and the following compiler options:</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;commonjs&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>commonjs<span class="pl-pds">"</span></span>,
}</pre></div>
<p dir="auto">A class expression being default exported will be incorrectly compiled into a named export instead.</p>
<p dir="auto">Example:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="export default class Foo {}"><pre class="notranslate"><span class="pl-k">export</span> <span class="pl-k">default</span> <span class="pl-k">class</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span><span class="pl-kos">}</span></pre></div>
<p dir="auto">compiles into:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class Foo {
}
exports.Foo = Foo;"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-v">Foo</span> <span class="pl-kos">{</span>
<span class="pl-kos">}</span>
<span class="pl-s1">exports</span><span class="pl-kos">.</span><span class="pl-c1">Foo</span> <span class="pl-c1">=</span> <span class="pl-v">Foo</span><span class="pl-kos">;</span></pre></div>