title: Jest mock and typescript
body: <p>i am writing a test for a function that wraps the fetch api. </p>
  
  <pre><code>const callAPI = (uri: string, options: RequestParams) =&gt; {
  
      let headers = { requestId: shortid.generate() };
  
      if (options.headers) {
          headers = { ...options.headers, ...headers};
      }
  
      const opts = {...options, ...{ headers }};
      return fetch(uri, opts);
  };
  </code></pre>
  
  <p>And the test for this function like this:</p>
  
  <pre><code>it('should add requestId to headers', () =&gt; {
      window.fetch = jest.fn();
      callAPI('localhost', { method: 'POST' });
  
      expect(window.fetch.mock.calls[0][1]).toHaveProperty('headers');
      expect(window.fetch.mock.calls[0][1].headers).toHaveProperty('requestId');
  });
  </code></pre>
  
  <p>The problem is that typescript does not recognize that fetch is mocked thus can not find mock property on window.fetch
  Here is the error:</p>
  
  <pre><code>[ts] Property 'mock' does not exist on type '(input: RequestInfo, init?: RequestInit) =&gt; Promise&lt;Response&gt;'.
  </code></pre>
  
  <p>How could i fix this?</p>