<p dir="auto">As of today specifying ES6 as a module format to transpile to with ES5 as a target will result in the "error TS1204: Cannot compile modules into 'es2015' when targeting 'ES5' or lower." error.</p>
<p dir="auto">But having ES6 modules in the ES5 output would be beneficial for ES6-based tree-shakers like <a href="https://github.com/rollup/rollup">Rollup</a>.</p>
<p dir="auto">Currently one can ES5 output with ES6 modules by using <code class="notranslate">ts.transpileModule(...)</code> but the output is broken in some cases. For example transpiling:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="ts.version // 1.7.4
ts.transpileModule('export class A {}', {
  compilerOptions: {
    target: ts.ScriptTarget.ES5,
    module: ts.ModuleKind.ES6
  }
})"><pre class="notranslate"><span class="pl-s1">ts</span><span class="pl-kos">.</span><span class="pl-c1">version</span> <span class="pl-c">// 1.7.4</span>
<span class="pl-s1">ts</span><span class="pl-kos">.</span><span class="pl-en">transpileModule</span><span class="pl-kos">(</span><span class="pl-s">'export class A {}'</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
  <span class="pl-c1">compilerOptions</span>: <span class="pl-kos">{</span>
    <span class="pl-c1">target</span>: <span class="pl-s1">ts</span><span class="pl-kos">.</span><span class="pl-c1">ScriptTarget</span><span class="pl-kos">.</span><span class="pl-c1">ES5</span><span class="pl-kos">,</span>
    <span class="pl-c1">module</span>: <span class="pl-s1">ts</span><span class="pl-kos">.</span><span class="pl-c1">ModuleKind</span><span class="pl-kos">.</span><span class="pl-c1">ES6</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span></pre></div>
<p dir="auto">yields:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var A = (function () {
    function A() {
    }
    return A;
})();
A = A;"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-v">A</span> <span class="pl-c1">=</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-k">function</span> <span class="pl-v">A</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">return</span> <span class="pl-v">A</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-v">A</span> <span class="pl-c1">=</span> <span class="pl-v">A</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Notice: <code class="notranslate">A = A;</code> which should probably be <code class="notranslate">export { A };</code></p>
<p dir="auto">In-depth discussion and more examples in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="118805237" data-permission-text="Title is private" data-url="https://github.com/rollup/rollup-plugin-typescript/issues/9" data-hovercard-type="issue" data-hovercard-url="/rollup/rollup-plugin-typescript/issues/9/hovercard" href="https://github.com/rollup/rollup-plugin-typescript/issues/9">rollup/rollup-plugin-typescript#9</a></p>
<p dir="auto">Given the above I've got <strong>a question</strong>: do you plan to support ES6 modules for ES5 output? If not are you planning to provide a TS-specific tree-shaking bundler?</p>
<p dir="auto">Possible duplicate of <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="134795461" data-permission-text="Title is private" data-url="https://github.com/microsoft/TypeScript/issues/7148" data-hovercard-type="issue" data-hovercard-url="/microsoft/TypeScript/issues/7148/hovercard" href="https://github.com/microsoft/TypeScript/issues/7148">#7148</a>, but it seems like it should be working according to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="129919547" data-permission-text="Title is private" data-url="https://github.com/microsoft/TypeScript/issues/6742" data-hovercard-type="pull_request" data-hovercard-url="/microsoft/TypeScript/pull/6742/hovercard" href="https://github.com/microsoft/TypeScript/pull/6742">#6742</a>.</p>
<p dir="auto"><strong>TypeScript Version:</strong></p>
<p dir="auto">1.8.7</p>
<p dir="auto"><strong>Code</strong></p>
<p dir="auto">File: <code class="notranslate">1.d.ts</code></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="declare module 'm1' {
  function x (): x.Test;

  namespace x {
    export interface Test {
      prop1: boolean;
    }
  }

  export = x;
}"><pre class="notranslate"><span class="pl-k">declare</span> module <span class="pl-s">'m1'</span> <span class="pl-kos">{</span>
  <span class="pl-k">function</span> <span class="pl-s1">x</span> <span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-s1">x</span><span class="pl-kos">.</span><span class="pl-smi">Test</span><span class="pl-kos">;</span>

  <span class="pl-k">namespace</span> <span class="pl-s1">x</span> <span class="pl-kos">{</span>
    <span class="pl-k">export</span> <span class="pl-k">interface</span> <span class="pl-smi">Test</span> <span class="pl-kos">{</span>
      <span class="pl-c1">prop1</span>: <span class="pl-smi">boolean</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-c1">=</span> <span class="pl-s1">x</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">File: <code class="notranslate">2.ts</code></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="/// &lt;reference path=&quot;./1.d.ts&quot; /&gt;

import m1 = require('m1');

declare module 'm1' {
  interface Test {
    prop2: boolean;
  }
}

m1().prop2 // `prop2` does not exist on type `Test`."><pre class="notranslate"><span class="pl-c">/// &lt;reference path="./1.d.ts" /&gt;</span>

<span class="pl-k">import</span> <span class="pl-s1">m1</span> <span class="pl-c1">=</span> require<span class="pl-kos">(</span><span class="pl-s">'m1'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-k">declare</span> module <span class="pl-s">'m1'</span> <span class="pl-kos">{</span>
  <span class="pl-k">interface</span> <span class="pl-smi">Test</span> <span class="pl-kos">{</span>
    <span class="pl-c1">prop2</span>: <span class="pl-smi">boolean</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-en">m1</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">prop2</span> <span class="pl-c">// `prop2` does not exist on type `Test`.</span></pre></div>
<p dir="auto"><strong>Expected behavior:</strong></p>
<p dir="auto">Interfaces should merge, giving me access to <code class="notranslate">prop2</code>.</p>
<p dir="auto"><strong>Actual behavior:</strong></p>
<p dir="auto">No <code class="notranslate">prop2</code> on interface <code class="notranslate">Test</code>.</p>