<p dir="auto"><strong>TypeScript Version:</strong></p>
<p dir="auto">1.8.7</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="/* foo.ts*/
export class Foo {
    name: string;
}

/*bar.ts*/
import {Foo} from './foo'
declare module './foo' {
    interface Foo {
        bar(): string;
    }
}

Foo.prototype.bar = function() {
    return this.name; // this's type is any
}"><pre class="notranslate"><span class="pl-c">/* foo.ts*/</span>
<span class="pl-k">export</span> <span class="pl-k">class</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
    <span class="pl-c1">name</span>: <span class="pl-smi">string</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-c">/*bar.ts*/</span>
<span class="pl-k">import</span> <span class="pl-kos">{</span><span class="pl-smi">Foo</span><span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'./foo'</span>
<span class="pl-k">declare</span> module <span class="pl-s">'./foo'</span> <span class="pl-kos">{</span>
    <span class="pl-k">interface</span> <span class="pl-smi">Foo</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-smi">string</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-smi">Foo</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">.</span><span class="pl-en">bar</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">name</span><span class="pl-kos">;</span> <span class="pl-c">// this's type is any</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><strong>Expected behavior:</strong><br>
The type of <code class="notranslate">this</code> in augment function <code class="notranslate">bar</code> is <code class="notranslate">any</code>.<br>
<strong>Actual behavior:</strong><br>
The type of <code class="notranslate">this</code> is <code class="notranslate">Foo</code>.</p>
<p dir="auto"><strong>TypeScript Version:</strong></p>
<p dir="auto">1.8.0</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="function transform&lt;T&gt;(func: (stuff: T) =&gt; any) {
    return null;
}

let f = ({a}) =&gt; 'foo';
transform(f); // success 
transform(({a}) =&gt; 'bar'); // error"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">transform</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-s1">func</span>: <span class="pl-kos">(</span><span class="pl-s1">stuff</span>: <span class="pl-smi">T</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-smi">any</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">return</span> <span class="pl-c1">null</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">let</span> <span class="pl-en">f</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span><span class="pl-kos">{</span>a<span class="pl-kos">}</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-s">'foo'</span><span class="pl-kos">;</span>
<span class="pl-en">transform</span><span class="pl-kos">(</span><span class="pl-s1">f</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// success </span>
<span class="pl-en">transform</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">{</span>a<span class="pl-kos">}</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-s">'bar'</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// error</span></pre></div>
<p dir="auto"><strong>Expected behavior:</strong><br>
Both cases should inference <code class="notranslate">T</code> as <code class="notranslate">{ a: any }</code>.</p>
<p dir="auto"><strong>Actual behavior:</strong><br>
If <code class="notranslate">func</code> is defined as a variable, it works fine. But if it is inlined, it doesn't work.</p>
<p dir="auto">Might be a duplicate of <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="54817143" data-permission-text="Title is private" data-url="https://github.com/microsoft/TypeScript/issues/1729" data-hovercard-type="issue" data-hovercard-url="/microsoft/TypeScript/issues/1729/hovercard" href="https://github.com/microsoft/TypeScript/issues/1729">#1729</a>, but this use case has no overload.</p>