<p dir="auto">Hi,</p>
<p dir="auto">When adding new functions to object prototype, <code class="notranslate">this</code> could be hard-typed in below scenario:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="interface Array&lt;T&gt; {
  first(): T;
}

Array.prototype.first = function() {
  return this.length &gt; 0 ? this[0] : undefined;
}"><pre class="notranslate"><span class="pl-k">interface</span> <span class="pl-smi">Array</span><span class="pl-c1">&lt;</span><span class="pl-smi">T</span><span class="pl-c1">&gt;</span> <span class="pl-kos">{</span>
  <span class="pl-c1">first</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">T</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-smi">Array</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">.</span><span class="pl-en">first</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">return</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">length</span> <span class="pl-c1">&gt;</span> <span class="pl-c1">0</span> ? <span class="pl-smi">this</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span> : <span class="pl-c1">undefined</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><code class="notranslate">this</code> is of type <code class="notranslate">any</code>, why it can't be of type <code class="notranslate">Array</code> ?</p>
<p dir="auto">typescript: 1.8.30</p>
<p dir="auto"><strong>TypeScript Version:</strong></p>
<p dir="auto">1.8.9</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="export class Configuration {
    private storage: string;

    constructor() {
        this.storage = &quot;InMemoryStorageProvider()&quot;;
    }

    public useLocalStorage(): void {
        // This method will be injected via the prototype.
    }    
}"><pre class="notranslate"><span class="pl-k">export</span> <span class="pl-k">class</span> <span class="pl-smi">Configuration</span> <span class="pl-kos">{</span>
    <span class="pl-k">private</span> <span class="pl-c1">storage</span>: <span class="pl-smi">string</span><span class="pl-kos">;</span>

    <span class="pl-en">constructor</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">storage</span> <span class="pl-c1">=</span> <span class="pl-s">"InMemoryStorageProvider()"</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>

    <span class="pl-k">public</span> <span class="pl-en">useLocalStorage</span><span class="pl-kos">(</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-c">// This method will be injected via the prototype.</span>
    <span class="pl-kos">}</span>    
<span class="pl-kos">}</span></pre></div>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import { Configuration } from './classes/Configuration';

Configuration.prototype.useLocalStorage = function() {
    this.storage = &quot;NodeFileStorageProvider&quot;
};"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-kos">{</span> <span class="pl-smi">Configuration</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'./classes/Configuration'</span><span class="pl-kos">;</span>

<span class="pl-smi">Configuration</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">.</span><span class="pl-en">useLocalStorage</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-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">storage</span> <span class="pl-c1">=</span> <span class="pl-s">"NodeFileStorageProvider"</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Expected behavior:</strong></p>
<p dir="auto">When walking the AST I use:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="let identifier: ts.Identifier = &lt;ts.Identifier&gt;node;
let identifierSymbol: ts.Symbol = this.checker.getSymbolAtLocation( identifier );"><pre class="notranslate"><code class="notranslate">let identifier: ts.Identifier = &lt;ts.Identifier&gt;node;
let identifierSymbol: ts.Symbol = this.checker.getSymbolAtLocation( identifier );
</code></pre></div>
<p dir="auto">to obtain the identifier and its possible associated symbol when the node is SyntaxKind.Identifier.</p>
<p dir="auto">for the first 2 references to the private property <code class="notranslate">storage</code>, I obtain the identifier and the symbol (which correctly have the same <code class="notranslate">Id</code>). With the prototype function assigned to useLocalStorage the reference to <code class="notranslate">storage</code> the call to <code class="notranslate">this.checker.getSymbolAtLocation( identifier )</code> does not return a symbol.</p>
<p dir="auto"><strong>Actual behavior:</strong></p>
<p dir="auto">I am using the AST to identify identifiers which may be minified/shortened. The 1st and 2nd reference to <code class="notranslate">storage</code> gets shortened as it is a private property.</p>
<p dir="auto">My expectation was that the reference to <code class="notranslate">storage</code> would have the same symbol ( not undefined ) as the other references to the <code class="notranslate">storage</code> property.</p>