title: How to extend Mocha's Context interface?
body: <p>Take the following code snippet:</p>
  
  <pre><code>import { Foo } from "./foo";
  
  export interface MyContext extends Mocha.Context {
    foo: Foo;
  }
  </code></pre>
  
  <p>This is in a project with the <a href="https://www.npmjs.com/package/@types/mocha" rel="nofollow noreferrer">@types/mocha</a> package installed, so that the <code>Mocha</code> namespace can be inferred by the compiler.</p>
  
  <p>Now, if I try to use this interface in a test suite:</p>
  
  <pre><code>import { MyContxt } from "../types/mocha";
  
  describe("my test suite", function() {
    it("should do something", function(this: MyContext) {
      ...
    });
  });
  </code></pre>
  
  <p>The TypeScript compiler throws the following error:</p>
  
  <blockquote>
    <p>No overload matches this call.</p>
  </blockquote>
  
  <p>I looked up the <a href="https://github.com/DefinitelyTyped/DefinitelyTyped/blob/bf720a41e4a4fcd9375e7ea545db191b8bea9184/types/mocha/index.d.ts#L2216-L2224" rel="nofollow noreferrer">source code</a>, and it seems that mocha expects any function passed to the <code>before</code>, <code>beforeEach</code>, <code>it</code>, etc., hooks to be linked to a <code>Context</code> type as defined in <code>@types/mocha</code> - it doesn't accept any descendant types.</p>
  
  <p>How can I go around this and extend the Mocha Context interface in my testing environment?</p>