title: Typescript errors when using jest mocks
body: <p>I have a previously-created <code>.js</code> file that mocks away some of our functions for <code>jest</code> test purposes. I'm migrating that to a <code>.ts</code> file:</p>
  
  <p><strong>Server.ts</strong></p>
  
  <pre><code>const Server = jest.genMockFromModule('../Server');
  
  Server.getAsync = Server.default.getAsync;
  // other REST-ful functions here
  
  export default Server;
  </code></pre>
  
  <p>I am getting the following errors:</p>
  
  <blockquote>
    <p>Property 'getAsync' does not exist on type '{}'</p>
    
    <p>Property 'default' does not exist on type '{}'</p>
  </blockquote>
  
  <p>Then, in a corresponding test file:</p>
  
  <p><strong>MyComponent.test.ts</strong></p>
  
  <pre><code>import Server from 'path/to/Server';
  
  jest.mock('path/to/Server');
  
  const dispatchMock = jest.fn();
  const getStateMock = jest.fn();
  
  describe('MyComponent.someFunction', () =&gt; {
      beforeEach(() =&gt; {
          jest.resetAllMocks();
      });
  
      it('Does the right stuff', () =&gt; {
          Server.getAsync.mockReturnValueOnce(Promise.resolve([{ key: 'value' }]));
          dispatchMock.mockImplementationOnce((promise) =&gt; promise);
          dispatchMock.mockImplementationOnce();
  
          return someFunction()(dispatchMock)
              .then(() =&gt; {
                  expect(Server.getAsync).toHaveBeenCalledTimes(1);
                  expect(Server.getAsync.mock.calls[0][0]).toBe('something');
              });
      });
  });
  </code></pre>
  
  <p>I am getting errors on <code>dispatchMock.mockImplementationOnce()</code></p>
  
  <blockquote>
    <p>Expected 1 arguments, but got 0. (method)
    jest.MockInstance&lt;{}>.mockImplementationOnce(fn: (...args: any[]) =>
    any): jest.Mock&lt;{}></p>
  </blockquote>
  
  <p>...on <code>Server.getAsync.mockReturnValueOnce</code></p>
  
  <blockquote>
    <p>Property 'mockReturnValueOnce' does not exist on type '(url: string,
    baseRoute?: string | null, loadingGenerator?: (isLoading: boolean) =>
    { type: strin...'.</p>
  </blockquote>
  
  <p>...and on <code>Server.getAsync.mock</code></p>
  
  <blockquote>
    <p>Property 'mock' does not exist on type '(url: string, baseRoute?:
    string | null, loadingGenerator?: (isLoading: boolean) => { type:
    strin...'.</p>
  </blockquote>
  
  <p>I've been pounding my head on this for a while so any help would be greatly appreciated.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Okay, I added <code>as any</code> to the end of the first line of my <code>Server.ts</code> file so now it looks like:</p>
  
  <pre><code>const Server = jest.genMockFromModule('../Server') as any;
  </code></pre>
  
  <p>That got rid of the first set of errors. Still facing the errors in my <code>.test.ts</code> file though.</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>I've noticed that when I run the actual jest tests, that they all pass even though there are TypeErrors. These issues don't appear to be related to actual tests.</p>