title: Extending supertest in Typescript
body: <p>I'm trying to create a extension on supertest.</p>
  
  <p>Using what I found in question <a href="https://stackoverflow.com/a/47682059/1233788">Extending SuperTest</a>. I have this working example on <code>javascript</code>:</p>
  
  <pre><code>const request = require('supertest');
  const Test = request.Test;
  
  Test.prototype.authenticate = function(user) {
    const {token, xsrfToken} = user.tokens;
  
    return this
     .set('Authorization', `Bearer ${token}`)
     .set('X-XSRF-TOKEN', xsrfToken);
  }
  </code></pre>
  
  <p>And inside a test block I can use:</p>
  
  <pre><code>request(app)
    .post('/user/settings')
    .authenticate(user)
    .send(...)
  </code></pre>
  
  <p>This works fine. The problem now is to use the extension in a <code>*.test.ts</code> file.</p>
  
  <p>As suggested in <a href="https://stackoverflow.com/a/40762463/1233788">Extend Express Request object using Typescript</a>, I try to create a file to use the typescript feature  <a href="https://www.typescriptlang.org/docs/handbook/declaration-merging.html" rel="nofollow noreferrer">Declaration Merging</a>.</p>
  
  <pre><code>// file location: ./src/types/supertest
  
  declare namespace supertest {
    export interface Test {
      authenticate(user: any): this; // I didn't put a type on user to simplify here.
    }
  }
  </code></pre>
  
  <p>and also changed my <code>tsconfig.json</code></p>
  
  <pre><code>{
    "compilerOptions": {
  
      ...
  
      "typeRoots": ["./src/types"],
  
      ...
  
    }
  }
  </code></pre>
  
  <p>But when I run <code>npx tsc</code></p>
  
  <pre><code>$ npx tsc
  src/api/user.test.ts:51:8 - error TS2551: Property 'authenticate' does not exist on type 'Test'.
  
  51       .authenticate(user);
            ~~~~~~~
  </code></pre>
  
  <p><strong>Question</strong><br>
  Is there a way to fix this on typescript environment?  </p>
  
  <p><strong>[EDIT]</strong><br>
  <strong>Extra Information (not necessarily useful):</strong><br>
  In the same project I have extensions on <code>express</code>, <code>chai</code> and <code>pdf-merge-js</code>. All of them works fine using the approach described above.</p>
  
  <p>There is something peculiar about <code>supertest</code> maybe about <code>@types/supertest</code> that is preventing it to work.  </p>
  
  <p>This is a little bit of the code in my project that already work's for express:</p>
  
  <pre><code>// file location: ./src/types/express
  import { ModelBase } from '../../models/base';
  
  declare global {
    namespace Express {
      export interface Response {
        model: (model: ModelBase) =&gt; this;
      }
    }
  }
  </code></pre>