<p dir="auto">Hi!</p>
<p dir="auto">I'm consuming declaration files from the node packages in my project so I'm not able to modify them.<br>
Therefore I opted to override module definition.</p>
<p dir="auto">I use redux and redux-thunk. Without this override of Dispatch type all my uses of dispatch will complain about wrong type (Correct behaviour). What redux-thunk does that it allows to dispatch to not dispatch object but also functions that can dispatch multiple objects.</p>
<p dir="auto"><strong>TypeScript Version:</strong></p>
<p dir="auto">1.8.10</p>
<p dir="auto"><strong>Code</strong><br>
// redux-dispatch-override.d.ts</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import * as redux from 'redux';

declare module 'redux' {
    export interface Dispatch&lt;S&gt; {
        &lt;R&gt;(asyncAction: (dispatch: Dispatch&lt;S&gt;, getState: () =&gt; S) =&gt; R): R;
    }
}"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-c1">*</span> <span class="pl-k">as</span> <span class="pl-s1">redux</span> <span class="pl-k">from</span> <span class="pl-s">'redux'</span><span class="pl-kos">;</span>

<span class="pl-k">declare</span> module <span class="pl-s">'redux'</span> <span class="pl-kos">{</span>
    <span class="pl-k">export</span> <span class="pl-k">interface</span> <span class="pl-smi">Dispatch</span><span class="pl-c1">&lt;</span><span class="pl-smi">S</span><span class="pl-c1">&gt;</span> <span class="pl-kos">{</span>
        <span class="pl-c1">&lt;</span><span class="pl-smi">R</span><span class="pl-c1">&gt;</span><span class="pl-kos">(</span><span class="pl-s1">asyncAction</span>: <span class="pl-kos">(</span><span class="pl-s1">dispatch</span>: <span class="pl-smi">Dispatch</span><span class="pl-kos">&lt;</span><span class="pl-smi">S</span><span class="pl-kos">&gt;</span><span class="pl-kos">,</span> <span class="pl-s1">getState</span>: <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-smi">S</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-smi">R</span><span class="pl-kos">)</span>: <span class="pl-smi">R</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><strong>Expected behavior:</strong><br>
Typescript compiler actually does accept this and will no longer throw errors which is very nice.</p>
<p dir="auto"><strong>Actual behavior:</strong><br>
On the other hand there is a problem with tsserver.<br>
In Webstorm tsserver will no longer consume definitions defined in redux node package. Instead it will try to find all definitions in this overriden declaration.</p>
<p dir="auto"><strong>TypeScript Version:</strong></p>
<p dir="auto">1.9.0-dev.20160518-1.0</p>
<p dir="auto"><strong>Code</strong></p>
<p dir="auto"><code class="notranslate">bar/index.ts</code>:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="export interface Bar {}"><pre class="notranslate"><span class="pl-k">export</span> <span class="pl-k">interface</span> <span class="pl-smi">Bar</span> <span class="pl-kos">{</span><span class="pl-kos">}</span></pre></div>
<p dir="auto"><code class="notranslate">foo/index.ts</code>:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import {Bar} from '../bar';

namespace Bar {
  export const foo = 3;
}

export const foo = Bar.foo;"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-kos">{</span><span class="pl-smi">Bar</span><span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'../bar'</span><span class="pl-kos">;</span>

<span class="pl-k">namespace</span> <span class="pl-smi">Bar</span> <span class="pl-kos">{</span>
  <span class="pl-k">export</span> <span class="pl-k">const</span> <span class="pl-s1">foo</span> <span class="pl-c1">=</span> <span class="pl-c1">3</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">export</span> <span class="pl-k">const</span> <span class="pl-s1">foo</span> <span class="pl-c1">=</span> <span class="pl-smi">Bar</span><span class="pl-kos">.</span><span class="pl-c1">foo</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Expected behavior:</strong></p>
<p dir="auto"><code class="notranslate">foo/index.js</code>:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&quot;use strict&quot;;
var bar_1 = require('../bar');
var Bar;
(function (Bar) {
    Bar.foo = 3;
})(Bar || (Bar = {}));
exports.foo = Bar.foo;"><pre class="notranslate"><span class="pl-s">"use strict"</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-s1">bar_1</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'../bar'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-v">Bar</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-v">Bar</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-v">Bar</span><span class="pl-kos">.</span><span class="pl-c1">foo</span> <span class="pl-c1">=</span> <span class="pl-c1">3</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">Bar</span> <span class="pl-c1">||</span> <span class="pl-kos">(</span><span class="pl-v">Bar</span> <span class="pl-c1">=</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-s1">exports</span><span class="pl-kos">.</span><span class="pl-c1">foo</span> <span class="pl-c1">=</span> <span class="pl-v">Bar</span><span class="pl-kos">.</span><span class="pl-c1">foo</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Actual behavior:</strong></p>
<p dir="auto"><code class="notranslate">foo/index.js</code>:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&quot;use strict&quot;;
var bar_1 = require('../bar');
var Bar;
(function (Bar) {
    Bar.foo = 3;
})(Bar || (Bar = {}));
exports.foo = bar_1.Bar.foo;"><pre class="notranslate"><span class="pl-s">"use strict"</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-s1">bar_1</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'../bar'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-v">Bar</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-v">Bar</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-v">Bar</span><span class="pl-kos">.</span><span class="pl-c1">foo</span> <span class="pl-c1">=</span> <span class="pl-c1">3</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">Bar</span> <span class="pl-c1">||</span> <span class="pl-kos">(</span><span class="pl-v">Bar</span> <span class="pl-c1">=</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-s1">exports</span><span class="pl-kos">.</span><span class="pl-c1">foo</span> <span class="pl-c1">=</span> <span class="pl-s1">bar_1</span><span class="pl-kos">.</span><span class="pl-c1">Bar</span><span class="pl-kos">.</span><span class="pl-c1">foo</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Notes:</strong><br>
This currently fails silently. At runtime <code class="notranslate">foo/index.js</code> will export <code class="notranslate">{foo: undefined}</code>. If merging a namespace declaration into a type name imported from another module is not allowed, then this should result in a compilation error. The issue I could find closest to this was <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="150956752" data-permission-text="Title is private" data-url="https://github.com/microsoft/TypeScript/issues/8288" data-hovercard-type="issue" data-hovercard-url="/microsoft/TypeScript/issues/8288/hovercard" href="https://github.com/microsoft/TypeScript/issues/8288">#8288</a>.</p>
<p dir="auto">This issue does not occur if <code class="notranslate">bar/index.ts</code> additionally exports a namespace named <code class="notranslate">Bar</code>; <code class="notranslate">tsc</code> reports <code class="notranslate">error TS2440: Import declaration conflicts with local declaration of 'Bar'</code> in such a scenario.</p>