<p dir="auto">tsc version 1.6.2</p>
<p dir="auto">Test case:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="interface ProblemMatcher {
    owner: string;
}

interface Task {
    problemMatchers: ProblemMatcher[];
}

let matcher: ProblemMatcher = {
    owner: 'ts'
};

(matcher as any).mySpecial = true;

class Parser {
    public process() {
        let task: Task;
        for(let matcher of task.problemMatchers) {
            if ((matcher as any).mySpecial) {
                // Do something.
            }
        }
    }
}"><pre class="notranslate"><span class="pl-k">interface</span> <span class="pl-smi">ProblemMatcher</span> <span class="pl-kos">{</span>
    <span class="pl-c1">owner</span>: <span class="pl-smi">string</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">interface</span> <span class="pl-smi">Task</span> <span class="pl-kos">{</span>
    <span class="pl-c1">problemMatchers</span>: <span class="pl-smi">ProblemMatcher</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">let</span> <span class="pl-s1">matcher</span>: <span class="pl-smi">ProblemMatcher</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
    <span class="pl-c1">owner</span>: <span class="pl-s">'ts'</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span>

<span class="pl-kos">(</span><span class="pl-s1">matcher</span> <span class="pl-k">as</span> <span class="pl-smi">any</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">mySpecial</span> <span class="pl-c1">=</span> <span class="pl-c1">true</span><span class="pl-kos">;</span>

<span class="pl-k">class</span> <span class="pl-smi">Parser</span> <span class="pl-kos">{</span>
    <span class="pl-k">public</span> <span class="pl-en">process</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">let</span> <span class="pl-s1">task</span>: <span class="pl-smi">Task</span><span class="pl-kos">;</span>
        <span class="pl-k">for</span><span class="pl-kos">(</span><span class="pl-k">let</span> <span class="pl-s1">matcher</span> <span class="pl-k">of</span> <span class="pl-s1">task</span><span class="pl-kos">.</span><span class="pl-c1">problemMatchers</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-kos">(</span><span class="pl-s1">matcher</span> <span class="pl-k">as</span> <span class="pl-smi">any</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">mySpecial</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
                <span class="pl-c">// Do something.</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">The compiler generates</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var matcher = {
    owner: 'ts'
};
matcher.mySpecial = true;
var Parser = (function () {
    function Parser() {
    }
    Parser.prototype.processOne = function () {
        var task;
        for (var _i = 0, _a = task.problemMatchers; _i &lt; _a.length; _i++) {
            var matcher_1 = _a[_i];
            if (matcher.mySpecial) {
            }
        }
    };
    Parser.prototype.processTwo = function () {
        var task;
        for (var _i = 0, _a = task.problemMatchers; _i &lt; _a.length; _i++) {
            var matcher_2 = _a[_i];
            if (matcher.mySpecial) {
            }
        }
    };
    return Parser;
})();"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">matcher</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
    <span class="pl-c1">owner</span>: <span class="pl-s">'ts'</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span>
<span class="pl-s1">matcher</span><span class="pl-kos">.</span><span class="pl-c1">mySpecial</span> <span class="pl-c1">=</span> <span class="pl-c1">true</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-v">Parser</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">Parser</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">Parser</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">.</span><span class="pl-en">processOne</span> <span class="pl-c1">=</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">var</span> <span class="pl-s1">task</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">0</span><span class="pl-kos">,</span> <span class="pl-s1">_a</span> <span class="pl-c1">=</span> <span class="pl-s1">task</span><span class="pl-kos">.</span><span class="pl-c1">problemMatchers</span><span class="pl-kos">;</span> <span class="pl-s1">_i</span> <span class="pl-c1">&lt;</span> <span class="pl-s1">_a</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-k">var</span> <span class="pl-s1">matcher_1</span> <span class="pl-c1">=</span> <span class="pl-s1">_a</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-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">matcher</span><span class="pl-kos">.</span><span class="pl-c1">mySpecial</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">Parser</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">.</span><span class="pl-en">processTwo</span> <span class="pl-c1">=</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">var</span> <span class="pl-s1">task</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">0</span><span class="pl-kos">,</span> <span class="pl-s1">_a</span> <span class="pl-c1">=</span> <span class="pl-s1">task</span><span class="pl-kos">.</span><span class="pl-c1">problemMatchers</span><span class="pl-kos">;</span> <span class="pl-s1">_i</span> <span class="pl-c1">&lt;</span> <span class="pl-s1">_a</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-k">var</span> <span class="pl-s1">matcher_2</span> <span class="pl-c1">=</span> <span class="pl-s1">_a</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-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">matcher</span><span class="pl-kos">.</span><span class="pl-c1">mySpecial</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-k">return</span> <span class="pl-v">Parser</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></pre></div>
<p dir="auto">The problematic code is If (matcher.mySpecial) ...  This must be if (matcher_2.mySpecial)</p>
<p dir="auto"><strong>foo.ts</strong></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="export function foo() { }"><pre class="notranslate"><span class="pl-k">export</span> <span class="pl-k">function</span> <span class="pl-en">foo</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>bar.ts</strong></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import { foo } from './foo';

(foo as any);"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-kos">{</span> <span class="pl-s1">foo</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'./foo'</span><span class="pl-kos">;</span>

<span class="pl-kos">(</span><span class="pl-s1">foo</span> <span class="pl-k">as</span> <span class="pl-smi">any</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>bar.js</strong></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var foo_1 = require('./foo');
foo;"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">foo_1</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'./foo'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">foo</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><code class="notranslate">(&lt;any&gt;foo)</code> works correctly btw.</p>