<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="interface Bank {
    balance: number;
    withdraw(x: number): number;
}

class PowellCountyBank implements Bank {
    balance: number = 0;

    withdraw(x) {
        return (this.balance - x);
    }
}

var b = new PowellCountyBank();

console.log(b.withdraw({}));
                     // ^ Expect type error here."><pre class="notranslate"><span class="pl-k">interface</span> <span class="pl-smi">Bank</span> <span class="pl-kos">{</span>
    <span class="pl-c1">balance</span>: <span class="pl-smi">number</span><span class="pl-kos">;</span>
    <span class="pl-c1">withdraw</span><span class="pl-kos">(</span><span class="pl-s1">x</span>: <span class="pl-smi">number</span><span class="pl-kos">)</span>: <span class="pl-smi">number</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">class</span> <span class="pl-smi">PowellCountyBank</span> <span class="pl-k">implements</span> <span class="pl-smi">Bank</span> <span class="pl-kos">{</span>
    <span class="pl-c1">balance</span>: <span class="pl-smi">number</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span><span class="pl-kos">;</span>

    <span class="pl-en">withdraw</span><span class="pl-kos">(</span><span class="pl-s1">x</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">return</span> <span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">balance</span> <span class="pl-c1">-</span> <span class="pl-s1">x</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">var</span> <span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">PowellCountyBank</span><span class="pl-kos">(</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">b</span><span class="pl-kos">.</span><span class="pl-en">withdraw</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-c">// ^ Expect type error here.</span></pre></div>
<p dir="auto">(<a href="http://www.typescriptlang.org/Playground#src=interface%20Bank%20%7B%0D%0A%09balance%3A%20number%3B%0D%0A%09withdraw%28x%3A%20number%29%3A%20number%3B%0D%0A%7D%0D%0A%0D%0Aclass%20PowellCountyBank%20implements%20Bank%20%7B%0D%0A%09balance%3A%20number%20%3D%200%3B%0D%0A%09%0D%0A%09withdraw%28x%29%20%7B%0D%0A%09%09return%20%28this.balance%20-%20x%29%3B%0D%0A%09%7D%0D%0A%7D%0D%0A%0D%0Avar%20b%20%3D%20new%20PowellCountyBank%28%29%3B%0D%0A%0D%0Aconsole.log%28b.withdraw%28%7B%7D%29%29%3B%0D%0A" rel="nofollow">Playground</a>)</p>
<p dir="auto">The implementation shows the return type of <code class="notranslate">withdraw</code> but not type for the parameter:</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/2061925/12765569/39a063da-c9cd-11e5-933c-880c44828a69.png"><img src="https://cloud.githubusercontent.com/assets/2061925/12765569/39a063da-c9cd-11e5-933c-880c44828a69.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">When a property has exactly one type from an <code class="notranslate">extends</code> or <code class="notranslate">implements</code> clause, we should contextually type that property's initializer by the type from the clause. For example:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="interface ThingListener {
    handleEvent: (x: MouseEvent) =&gt; void;
}

class Foo implements ThingListener {
    handleEvent = x =&gt; {
        // No error, but this code is incorrect
        console.log(x.timestamp);
    }
}"><pre class="notranslate"><span class="pl-k">interface</span> <span class="pl-smi">ThingListener</span> <span class="pl-kos">{</span>
    <span class="pl-c1">handleEvent</span>: <span class="pl-kos">(</span><span class="pl-s1">x</span>: <span class="pl-smi">MouseEvent</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-smi"><span class="pl-k">void</span></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-k">implements</span> <span class="pl-smi">ThingListener</span> <span class="pl-kos">{</span>
    <span class="pl-c1">handleEvent</span> <span class="pl-c1">=</span> <span class="pl-s1">x</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
        <span class="pl-c">// No error, but this code is incorrect</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">timestamp</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">Ideally we could take this one step further when widening. The following behavior is also undesirable:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="interface HasLength {
    length: number
}

class Foo implements HasLength {
    // length: any, not really what we intended
    length = undefined;
}

var x = new Foo();
x.length = 'wat'; // should not be allowed"><pre class="notranslate"><span class="pl-k">interface</span> <span class="pl-smi">HasLength</span> <span class="pl-kos">{</span>
    <span class="pl-c1">length</span>: <span class="pl-smi">number</span>
<span class="pl-kos">}</span>

<span class="pl-k">class</span> <span class="pl-smi">Foo</span> <span class="pl-k">implements</span> <span class="pl-smi">HasLength</span> <span class="pl-kos">{</span>
    <span class="pl-c">// length: any, not really what we intended</span>
    <span class="pl-c1">length</span> <span class="pl-c1">=</span> <span class="pl-c1">undefined</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">var</span> <span class="pl-s1">x</span> <span class="pl-c1">=</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-s1">x</span><span class="pl-kos">.</span><span class="pl-c1">length</span> <span class="pl-c1">=</span> <span class="pl-s">'wat'</span><span class="pl-kos">;</span> <span class="pl-c">// should not be allowed</span></pre></div>
<p dir="auto">e.g. <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="91669978" data-permission-text="Title is private" data-url="https://github.com/microsoft/TypeScript/issues/3666" data-hovercard-type="issue" data-hovercard-url="/microsoft/TypeScript/issues/3666/hovercard" href="https://github.com/microsoft/TypeScript/issues/3666">#3666</a></p>