title: Typescript - Mock interface with mapped types
body: <p>For testing purpose, I'd like to be able to create an object implementing an interface, only with function I need for my test, without having to manually maintain a mock object with all possible properties. Generally, I'm using one function at a time, so don't need to define all others but I don't want TS to keep complaining about missing properties.</p>
  
  <p>For example, I have an interface <code>IFoo</code> :</p>
  
  <pre><code>interface IFoo {
      myFunc(): string;
      otherFunc(): number;
  }
  </code></pre>
  
  <p>I tried to create a mapped type, which assign <code>jest.Mock&lt;{}&gt;</code> to all properties of <code>IFoo</code></p>
  
  <pre><code>type Mockify&lt;T&gt; = {
      [P in keyof T]: jest.Mock&lt;{}&gt;
  };
  </code></pre>
  
  <p>Calling it like this:</p>
  
  <pre><code>const mockFoo: Mockify&lt;IFoo&gt; = {
      otherFunc: {
          // Mocked function behavior
      }
  }
  </code></pre>
  
  <p>The problem with this approach is that TS complains about the missing <code>myFunc</code> property on the object passed to Mockify.</p>
  
  <p>I also tried <code>Mockify&lt;Partial&lt;IFoo&gt;&gt;</code> to ignore missing properties, but then my type defintion is different from <code>IFoo</code> and some other functions depending of <code>IFoo</code> are complaining.
  I could also define all properties as optionnal, but conceptually I don't like that.</p>
  
  <p>I have the feeling that mapped types could make the job, but I maybe don't have the right approach.</p>
  
  <p>Thanks for your help!</p>