<p dir="auto">This should compile without errors:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="declare function getDBObjectById(id: number): DBObject;
declare function bar(arg: DBObject): void;
function foo(arg: number | DBObject) {
  if (arg instanceof DBObject) {
    bar(arg)
  } else {
    bar(getDBObjectById(arg) // error TS2345: Argument of type 'number | DBObject' is not assignable to parameter of type 'number'.
                             // Type 'DBObject' is not assignable to type 'number'.
  }
}"><pre class="notranslate"><span class="pl-k">declare</span> <span class="pl-k">function</span> <span class="pl-s1">getDBObjectById</span><span class="pl-kos">(</span><span class="pl-s1">id</span>: <span class="pl-smi">number</span><span class="pl-kos">)</span>: <span class="pl-smi">DBObject</span><span class="pl-kos">;</span>
<span class="pl-k">declare</span> <span class="pl-k">function</span> <span class="pl-s1">bar</span><span class="pl-kos">(</span><span class="pl-s1">arg</span>: <span class="pl-smi">DBObject</span><span class="pl-kos">)</span>: <span class="pl-smi"><span class="pl-k">void</span></span><span class="pl-kos">;</span>
<span class="pl-k">function</span> <span class="pl-en">foo</span><span class="pl-kos">(</span><span class="pl-s1">arg</span>: <span class="pl-smi">number</span> <span class="pl-c1">|</span> <span class="pl-smi">DBObject</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">arg</span> <span class="pl-k">instanceof</span> <span class="pl-smi">DBObject</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-en">bar</span><span class="pl-kos">(</span><span class="pl-s1">arg</span><span class="pl-kos">)</span>
  <span class="pl-kos">}</span> <span class="pl-k">else</span> <span class="pl-kos">{</span>
    <span class="pl-c1">bar</span><span class="pl-kos">(</span><span class="pl-en">getDBObjectById</span><span class="pl-kos">(</span><span class="pl-s1">arg</span><span class="pl-kos">)</span> <span class="pl-c">// error TS2345: Argument of type 'number | DBObject' is not assignable to parameter of type 'number'.</span>
                             <span class="pl-c">// Type 'DBObject' is not assignable to type 'number'.</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Hi,</p>
<p dir="auto"><strong>TS Version</strong>: 1.4</p>
<p dir="auto">In the following:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class Bar {
    bar ='bar';
}

class Foo {
    foo = 100;
}

function f1(x: Bar|Foo) {

    if(x instanceof Bar){
        console.log(x.bar);
    }
    else {
        console.log(x.foo); // Error: inferred as Bar|Foo
    }   
}
 f1(new Bar()); // bar
 f1(new Foo()); // 100"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-smi">Bar</span> <span class="pl-kos">{</span>
    <span class="pl-c1">bar</span> <span class="pl-c1">=</span><span class="pl-s">'bar'</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">class</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
    <span class="pl-c1">foo</span> <span class="pl-c1">=</span> <span class="pl-c1">100</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">function</span> <span class="pl-en">f1</span><span class="pl-kos">(</span><span class="pl-s1">x</span>: <span class="pl-smi">Bar</span><span class="pl-c1">|</span><span class="pl-smi">Foo</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>

    <span class="pl-k">if</span><span class="pl-kos">(</span><span class="pl-s1">x</span> <span class="pl-k">instanceof</span> <span class="pl-smi">Bar</span><span class="pl-kos">)</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">x</span><span class="pl-kos">.</span><span class="pl-c1">bar</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
    <span class="pl-k">else</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">x</span><span class="pl-kos">.</span><span class="pl-c1">foo</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// Error: inferred as Bar|Foo</span>
    <span class="pl-kos">}</span>   
<span class="pl-kos">}</span>
 <span class="pl-en">f1</span><span class="pl-kos">(</span><span class="pl-k">new</span> <span class="pl-smi">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-c">// bar</span>
 <span class="pl-en">f1</span><span class="pl-kos">(</span><span class="pl-k">new</span> <span class="pl-smi">Foo</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// 100</span></pre></div>
<p dir="auto">is there any reason why in the <code class="notranslate">else</code> block we are failing to narrow the type to <code class="notranslate">Foo</code>?</p>