<p dir="auto"><strong>TypeScript Version:</strong></p>
<p dir="auto">Lastest Commit</p>
<p dir="auto"><strong>Code</strong></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const a = [5, 6, &quot;7&quot;, &quot;8&quot;]
const b = a.filter(x =&gt; typeof x === &quot;number&quot;)
"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-c1">5</span><span class="pl-kos">,</span> <span class="pl-c1">6</span><span class="pl-kos">,</span> <span class="pl-s">"7"</span><span class="pl-kos">,</span> <span class="pl-s">"8"</span><span class="pl-kos">]</span>
<span class="pl-k">const</span> <span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-s1">a</span><span class="pl-kos">.</span><span class="pl-en">filter</span><span class="pl-kos">(</span><span class="pl-s1">x</span> <span class="pl-c1">=&gt;</span> <span class="pl-k">typeof</span> <span class="pl-s1">x</span> <span class="pl-c1">===</span> <span class="pl-s">"number"</span><span class="pl-kos">)</span></pre></div>
<p dir="auto"><strong>Expected behavior:</strong><br>
b is <code class="notranslate">number[]</code><br>
<strong>Actual behavior:</strong><br>
b is <code class="notranslate">(number|string)[]</code></p>
<p dir="auto"><strong>TypeScript Version:</strong></p>
<p dir="auto">nightly (1.9.0-dev.20160323)</p>
<p dir="auto"><strong>Code</strong></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="let numbers: number[] =
    [1, '2', 3, '4'].filter(x =&gt; typeof x !== 'string');

declare function isNumber(arg: any): arg is number;
let numbers2: number[] = [1, '2', 3, '4'].filter(isNumber);"><pre class="notranslate"><span class="pl-k">let</span> <span class="pl-s1">numbers</span>: <span class="pl-smi">number</span><span class="pl-kos">[</span><span class="pl-kos">]</span> <span class="pl-c1">=</span>
    <span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-s">'2'</span><span class="pl-kos">,</span> <span class="pl-c1">3</span><span class="pl-kos">,</span> <span class="pl-s">'4'</span><span class="pl-kos">]</span><span class="pl-kos">.</span><span class="pl-en">filter</span><span class="pl-kos">(</span><span class="pl-s1">x</span> <span class="pl-c1">=&gt;</span> <span class="pl-k">typeof</span> <span class="pl-s1">x</span> <span class="pl-c1">!==</span> <span class="pl-s">'string'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-k">declare</span> <span class="pl-k">function</span> <span class="pl-s1">isNumber</span><span class="pl-kos">(</span><span class="pl-s1">arg</span>: <span class="pl-smi">any</span><span class="pl-kos">)</span>: <span class="pl-s1">arg</span> is <span class="pl-smi">number</span><span class="pl-kos">;</span>
<span class="pl-k">let</span> <span class="pl-s1">numbers2</span>: <span class="pl-smi">number</span><span class="pl-kos">[</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-s">'2'</span><span class="pl-kos">,</span> <span class="pl-c1">3</span><span class="pl-kos">,</span> <span class="pl-s">'4'</span><span class="pl-kos">]</span><span class="pl-kos">.</span><span class="pl-en">filter</span><span class="pl-kos">(</span><span class="pl-s1">isNumber</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><a href="http://www.typescriptlang.org/Playground#src=let%20numbers%3A%20number%5B%5D%20%3D%0A%20%20%20%20%5B1%2C%20'2'%2C%203%2C%20'4'%5D.filter%28x%20%3D%3E%20typeof%20x%20!%3D%3D%20'string'%29%3B%0A%0Adeclare%20function%20isNumber%28arg%3A%20any%29%3A%20arg%20is%20number%3B%0Alet%20numbers2%3A%20number%5B%5D%20%3D%20%5B1%2C%20'2'%2C%203%2C%20'4'%5D.filter%28isNumber%29%3B" rel="nofollow">Playground</a></p>
<p dir="auto"><strong>Expected behavior:</strong><br>
.filter with a type guard returns an array of the specified type. This would be especially useful with <code class="notranslate">--strictNullChecks</code>, so we could do something like <code class="notranslate">foo.map(maybeReturnsNull).filter(x =&gt; x != null)....</code></p>
<p dir="auto"><strong>Actual behavior:</strong><br>
.filter returns an array of the same type, and the two <code class="notranslate">let</code>s above are errors.</p>