<p dir="auto">Hi. Please see the question I have made here for a description of the problem.</p>
<p dir="auto"><a href="http://stackoverflow.com/questions/34546446/flattening-typescript-typings-or-interfaces" rel="nofollow">http://stackoverflow.com/questions/34546446/flattening-typescript-typings-or-interfaces</a></p>
<p dir="auto">Here's the post:</p>
<p dir="auto">As a TypeScript developer, I have become too used to "Duplicate identifier" issues when working with <code class="notranslate">.d.ts</code> files.</p>
<p dir="auto">Most recently, this occurred because I needed both the typings (<code class="notranslate">.d.ts</code> files) of Angular 2, and Parse.</p>
<p dir="auto">Angular 2 doesn't distribute their <code class="notranslate">.d.ts</code> files through <code class="notranslate">DefinitelyTyped</code>, so I had to fetch Angular 2 through NPM which includes the source files as well.</p>
<p dir="auto">Now, Parse's <code class="notranslate">.d.ts</code> come from <code class="notranslate">DefinitelyTyped</code>. Fine - so far, so good.</p>
<p dir="auto">The issue then arises because both of these libraries depend on Node JS typings. The Node JS typings of Parse are located in the <code class="notranslate">typings</code> folder, whereas the Node JS typings of Angular 2 are located in a subfolder under <code class="notranslate">node_modules/angular2</code>.</p>
<p dir="auto">This gives me a huge amount of duplicate identifier issues when compiling.</p>
<h3 dir="auto">So, the big question(s)</h3>
- Can I flatten `.d.ts` files so that it doesn't have duplicates somehow?
- Can I somehow make the TypeScript compiler ignore duplicate interface definitions?
<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">Transpiling <code class="notranslate">_apply.js</code> of <code class="notranslate">lodash-es@4.6.1</code> with the command</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="tsc --allowJs _apply.js --out apply.js -m amd"><pre class="notranslate"><code class="notranslate">tsc --allowJs _apply.js --out apply.js -m amd
</code></pre></div>
<p dir="auto">breaks the code. Apparently, the (arguably invalid) <code class="notranslate">@param {...*} args</code> JSDoc comment causes the TypeScript compiler to generate code as if the parameter declaration was <code class="notranslate">apply(func, thisArg, ...args)</code>, although it is not.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="/**
 * A faster alternative to `Function#apply`, this function invokes `func`
 * with the `this` binding of `thisArg` and the arguments of `args`.
 *
 * @private
 * @param {Function} func The function to invoke.
 * @param {*} thisArg The `this` binding of `func`.
 * @param {...*} args The arguments to invoke `func` with.
 * @returns {*} Returns the result of `func`.
 */
function apply(func, thisArg, args) {
  var length = args.length;
  switch (length) {
    case 0: return func.call(thisArg);
    case 1: return func.call(thisArg, args[0]);
    case 2: return func.call(thisArg, args[0], args[1]);
    case 3: return func.call(thisArg, args[0], args[1], args[2]);
  }
  return func.apply(thisArg, args);
}

export default apply;"><pre class="notranslate"><span class="pl-c">/**</span>
<span class="pl-c"> * A faster alternative to `Function#apply`, this function invokes `func`</span>
<span class="pl-c"> * with the `this` binding of `thisArg` and the arguments of `args`.</span>
<span class="pl-c"> *</span>
<span class="pl-c"> * <span class="pl-k">@private</span></span>
<span class="pl-c"> * <span class="pl-k">@param</span> {<span class="pl-smi">Function</span>} func The function to invoke.</span>
<span class="pl-c"> * <span class="pl-k">@param</span> {<span class="pl-smi">*</span>} thisArg The `this` binding of `func`.</span>
<span class="pl-c"> * <span class="pl-k">@param</span> {<span class="pl-smi">...*</span>} args The arguments to invoke `func` with.</span>
<span class="pl-c"> * <span class="pl-k">@returns</span> {<span class="pl-smi">*</span>} Returns the result of `func`.</span>
<span class="pl-c"> */</span>
<span class="pl-k">function</span> <span class="pl-en">apply</span><span class="pl-kos">(</span><span class="pl-s1">func</span><span class="pl-kos">,</span> <span class="pl-s1">thisArg</span><span class="pl-kos">,</span> <span class="pl-s1">args</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">var</span> <span class="pl-s1">length</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span><span class="pl-kos">.</span><span class="pl-c1">length</span><span class="pl-kos">;</span>
  <span class="pl-k">switch</span> <span class="pl-kos">(</span><span class="pl-s1">length</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">case</span> <span class="pl-c1">0</span>: <span class="pl-k">return</span> <span class="pl-s1">func</span><span class="pl-kos">.</span><span class="pl-en">call</span><span class="pl-kos">(</span><span class="pl-s1">thisArg</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">case</span> <span class="pl-c1">1</span>: <span class="pl-k">return</span> <span class="pl-s1">func</span><span class="pl-kos">.</span><span class="pl-en">call</span><span class="pl-kos">(</span><span class="pl-s1">thisArg</span><span class="pl-kos">,</span> <span class="pl-s1">args</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">case</span> <span class="pl-c1">2</span>: <span class="pl-k">return</span> <span class="pl-s1">func</span><span class="pl-kos">.</span><span class="pl-en">call</span><span class="pl-kos">(</span><span class="pl-s1">thisArg</span><span class="pl-kos">,</span> <span class="pl-s1">args</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-s1">args</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-k">case</span> <span class="pl-c1">3</span>: <span class="pl-k">return</span> <span class="pl-s1">func</span><span class="pl-kos">.</span><span class="pl-en">call</span><span class="pl-kos">(</span><span class="pl-s1">thisArg</span><span class="pl-kos">,</span> <span class="pl-s1">args</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-s1">args</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-s1">args</span><span class="pl-kos">[</span><span class="pl-c1">2</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-s1">func</span><span class="pl-kos">.</span><span class="pl-en">apply</span><span class="pl-kos">(</span><span class="pl-s1">thisArg</span><span class="pl-kos">,</span> <span class="pl-s1">args</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">default</span> <span class="pl-s1">apply</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Expected behavior:</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="define(&quot;_apply&quot;, [&quot;require&quot;, &quot;exports&quot;], function (require, exports) {
    &quot;use strict&quot;;
    /**
     * A faster alternative to `Function#apply`, this function invokes `func`
     * with the `this` binding of `thisArg` and the arguments of `args`.
     *
     * @private
     * @param {Function} func The function to invoke.
     * @param {*} thisArg The `this` binding of `func`.
     * @param {...*} args The arguments to invoke `func` with.
     * @returns {*} Returns the result of `func`.
     */
    function apply(func, thisArg, args) {
        var length = args.length;
        switch (length) {
            case 0: return func.call(thisArg);
            case 1: return func.call(thisArg, args[0]);
            case 2: return func.call(thisArg, args[0], args[1]);
            case 3: return func.call(thisArg, args[0], args[1], args[2]);
        }
        return func.apply(thisArg, args);
    }
    exports.__esModule = true;
    exports[&quot;default&quot;] = apply;
});"><pre class="notranslate"><span class="pl-en">define</span><span class="pl-kos">(</span><span class="pl-s">"_apply"</span><span class="pl-kos">,</span> <span class="pl-kos">[</span><span class="pl-s">"require"</span><span class="pl-kos">,</span> <span class="pl-s">"exports"</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">require</span><span class="pl-kos">,</span> <span class="pl-s1">exports</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-c">/**</span>
<span class="pl-c">     * A faster alternative to `Function#apply`, this function invokes `func`</span>
<span class="pl-c">     * with the `this` binding of `thisArg` and the arguments of `args`.</span>
<span class="pl-c">     *</span>
<span class="pl-c">     * <span class="pl-k">@private</span></span>
<span class="pl-c">     * <span class="pl-k">@param</span> {<span class="pl-smi">Function</span>} func The function to invoke.</span>
<span class="pl-c">     * <span class="pl-k">@param</span> {<span class="pl-smi">*</span>} thisArg The `this` binding of `func`.</span>
<span class="pl-c">     * <span class="pl-k">@param</span> {<span class="pl-smi">...*</span>} args The arguments to invoke `func` with.</span>
<span class="pl-c">     * <span class="pl-k">@returns</span> {<span class="pl-smi">*</span>} Returns the result of `func`.</span>
<span class="pl-c">     */</span>
    <span class="pl-k">function</span> <span class="pl-en">apply</span><span class="pl-kos">(</span><span class="pl-s1">func</span><span class="pl-kos">,</span> <span class="pl-s1">thisArg</span><span class="pl-kos">,</span> <span class="pl-s1">args</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">var</span> <span class="pl-s1">length</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span><span class="pl-kos">.</span><span class="pl-c1">length</span><span class="pl-kos">;</span>
        <span class="pl-k">switch</span> <span class="pl-kos">(</span><span class="pl-s1">length</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-k">case</span> <span class="pl-c1">0</span>: <span class="pl-k">return</span> <span class="pl-s1">func</span><span class="pl-kos">.</span><span class="pl-en">call</span><span class="pl-kos">(</span><span class="pl-s1">thisArg</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
            <span class="pl-k">case</span> <span class="pl-c1">1</span>: <span class="pl-k">return</span> <span class="pl-s1">func</span><span class="pl-kos">.</span><span class="pl-en">call</span><span class="pl-kos">(</span><span class="pl-s1">thisArg</span><span class="pl-kos">,</span> <span class="pl-s1">args</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
            <span class="pl-k">case</span> <span class="pl-c1">2</span>: <span class="pl-k">return</span> <span class="pl-s1">func</span><span class="pl-kos">.</span><span class="pl-en">call</span><span class="pl-kos">(</span><span class="pl-s1">thisArg</span><span class="pl-kos">,</span> <span class="pl-s1">args</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-s1">args</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-k">case</span> <span class="pl-c1">3</span>: <span class="pl-k">return</span> <span class="pl-s1">func</span><span class="pl-kos">.</span><span class="pl-en">call</span><span class="pl-kos">(</span><span class="pl-s1">thisArg</span><span class="pl-kos">,</span> <span class="pl-s1">args</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-s1">args</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-s1">args</span><span class="pl-kos">[</span><span class="pl-c1">2</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-s1">func</span><span class="pl-kos">.</span><span class="pl-en">apply</span><span class="pl-kos">(</span><span class="pl-s1">thisArg</span><span class="pl-kos">,</span> <span class="pl-s1">args</span><span class="pl-kos">)</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">__esModule</span> <span class="pl-c1">=</span> <span class="pl-c1">true</span><span class="pl-kos">;</span>
    <span class="pl-s1">exports</span><span class="pl-kos">[</span><span class="pl-s">"default"</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-s1">apply</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"><strong>Actual behavior:</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="define(&quot;_apply&quot;, [&quot;require&quot;, &quot;exports&quot;], function (require, exports) {
    &quot;use strict&quot;;
    /**
     * A faster alternative to `Function#apply`, this function invokes `func`
     * with the `this` binding of `thisArg` and the arguments of `args`.
     *
     * @private
     * @param {Function} func The function to invoke.
     * @param {*} thisArg The `this` binding of `func`.
     * @param {...*} args The arguments to invoke `func` with.
     * @returns {*} Returns the result of `func`.
     */
    function apply(func, thisArg) {
        var args = [];
        for (var _i = 2; _i &lt; arguments.length; _i++) {
            args[_i - 2] = arguments[_i];
        }
        var length = args.length;
        switch (length) {
            case 0: return func.call(thisArg);
            case 1: return func.call(thisArg, args[0]);
            case 2: return func.call(thisArg, args[0], args[1]);
            case 3: return func.call(thisArg, args[0], args[1], args[2]);
        }
        return func.apply(thisArg, args);
    }
    exports.__esModule = true;
    exports[&quot;default&quot;] = apply;
});"><pre class="notranslate"><span class="pl-en">define</span><span class="pl-kos">(</span><span class="pl-s">"_apply"</span><span class="pl-kos">,</span> <span class="pl-kos">[</span><span class="pl-s">"require"</span><span class="pl-kos">,</span> <span class="pl-s">"exports"</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">require</span><span class="pl-kos">,</span> <span class="pl-s1">exports</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-c">/**</span>
<span class="pl-c">     * A faster alternative to `Function#apply`, this function invokes `func`</span>
<span class="pl-c">     * with the `this` binding of `thisArg` and the arguments of `args`.</span>
<span class="pl-c">     *</span>
<span class="pl-c">     * <span class="pl-k">@private</span></span>
<span class="pl-c">     * <span class="pl-k">@param</span> {<span class="pl-smi">Function</span>} func The function to invoke.</span>
<span class="pl-c">     * <span class="pl-k">@param</span> {<span class="pl-smi">*</span>} thisArg The `this` binding of `func`.</span>
<span class="pl-c">     * <span class="pl-k">@param</span> {<span class="pl-smi">...*</span>} args The arguments to invoke `func` with.</span>
<span class="pl-c">     * <span class="pl-k">@returns</span> {<span class="pl-smi">*</span>} Returns the result of `func`.</span>
<span class="pl-c">     */</span>
    <span class="pl-k">function</span> <span class="pl-en">apply</span><span class="pl-kos">(</span><span class="pl-s1">func</span><span class="pl-kos">,</span> <span class="pl-s1">thisArg</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">var</span> <span class="pl-s1">args</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
        <span class="pl-k">for</span> <span class="pl-kos">(</span><span class="pl-k">var</span> <span class="pl-s1">_i</span> <span class="pl-c1">=</span> <span class="pl-c1">2</span><span class="pl-kos">;</span> <span class="pl-s1">_i</span> <span class="pl-c1">&lt;</span> <span class="pl-smi">arguments</span><span class="pl-kos">.</span><span class="pl-c1">length</span><span class="pl-kos">;</span> <span class="pl-s1">_i</span><span class="pl-c1">++</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-s1">args</span><span class="pl-kos">[</span><span class="pl-s1">_i</span> <span class="pl-c1">-</span> <span class="pl-c1">2</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-smi">arguments</span><span class="pl-kos">[</span><span class="pl-s1">_i</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">length</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span><span class="pl-kos">.</span><span class="pl-c1">length</span><span class="pl-kos">;</span>
        <span class="pl-k">switch</span> <span class="pl-kos">(</span><span class="pl-s1">length</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-k">case</span> <span class="pl-c1">0</span>: <span class="pl-k">return</span> <span class="pl-s1">func</span><span class="pl-kos">.</span><span class="pl-en">call</span><span class="pl-kos">(</span><span class="pl-s1">thisArg</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
            <span class="pl-k">case</span> <span class="pl-c1">1</span>: <span class="pl-k">return</span> <span class="pl-s1">func</span><span class="pl-kos">.</span><span class="pl-en">call</span><span class="pl-kos">(</span><span class="pl-s1">thisArg</span><span class="pl-kos">,</span> <span class="pl-s1">args</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
            <span class="pl-k">case</span> <span class="pl-c1">2</span>: <span class="pl-k">return</span> <span class="pl-s1">func</span><span class="pl-kos">.</span><span class="pl-en">call</span><span class="pl-kos">(</span><span class="pl-s1">thisArg</span><span class="pl-kos">,</span> <span class="pl-s1">args</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-s1">args</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-k">case</span> <span class="pl-c1">3</span>: <span class="pl-k">return</span> <span class="pl-s1">func</span><span class="pl-kos">.</span><span class="pl-en">call</span><span class="pl-kos">(</span><span class="pl-s1">thisArg</span><span class="pl-kos">,</span> <span class="pl-s1">args</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-s1">args</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-s1">args</span><span class="pl-kos">[</span><span class="pl-c1">2</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-s1">func</span><span class="pl-kos">.</span><span class="pl-en">apply</span><span class="pl-kos">(</span><span class="pl-s1">thisArg</span><span class="pl-kos">,</span> <span class="pl-s1">args</span><span class="pl-kos">)</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">__esModule</span> <span class="pl-c1">=</span> <span class="pl-c1">true</span><span class="pl-kos">;</span>
    <span class="pl-s1">exports</span><span class="pl-kos">[</span><span class="pl-s">"default"</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-s1">apply</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">I've not been able to reproduce this in the TypeScript playground (currently running 1.8.2), which suggests a regression somewhere between 1.8.2 and 1.8.7.</p>