title: 'this' implicitly has type 'any' because it does not have a type annotation
body: <p>When I enable <code>noImplicitThis</code> in <code>tsconfig.json</code>, I get this error for the following code:</p>
  
  <blockquote>
  <pre><code>'this' implicitly has type 'any' because it does not have a type annotation.
  </code></pre>
  </blockquote>
  
  <pre><code>class Foo implements EventEmitter {
    on(name: string, fn: Function) { }
    emit(name: string) { }
  }
  
  const foo = new Foo();
  foo.on('error', function(err: any) {
    console.log(err);
    this.emit('end');  // error: `this` implicitly has type `any`
  });
  </code></pre>
  
  <p>Adding a typed <code>this</code> to the callback parameters results in the same error:</p>
  
  <pre><code>foo.on('error', (this: Foo, err: any) =&gt; { // error: `this` implicitly has type `any`
  </code></pre>
  
  <p>A workaround is to replace <code>this</code> with the object:</p>
  
  <pre><code>foo.on('error', (err: any) =&gt; {
    console.log(err);
    foo.emit('end');
  });
  </code></pre>
  
  <p>But what is the proper fix for this error?</p>
  
  <hr>
  
  <p><strong>UPDATE:</strong> It turns out adding a typed <code>this</code> to the callback indeed addresses the error. I was seeing the error because I was using an arrow function with a type annotation for <code>this</code>:</p>
  
  <p><a href="https://i.stack.imgur.com/k4dmb.png" rel="noreferrer"><img src="https://i.stack.imgur.com/k4dmb.png" alt="typescript playground"></a></p>