title: How can I augment a typescript interface using a type exported from another .d.ts file?
body: <p>Here is my use case:</p>
  
  <p>We have a very lightweight abstraction around our Promise library because we've changed it several times now for various reasons and we prefer not to have to change the code throughout our application.</p>
  
  <p>I want to add a middleware to the express.Request instance which I can easily do by augmenting the interface, like so:</p>
  
  <pre><code>declare namespace Express {
      export interface Request {
          loginP(user: any): void;
      }
  }
  </code></pre>
  
  <p>Put this in a .d.ts file by itself and everything works great, which is awesome.</p>
  
  <p>HOWEVER.  Here is my trouble; in my abstraction, I re-export the interface of the promise library we are using so that we can use it throughout the application and have good type checking without requiring that everywhere know where it came from:</p>
  
  <pre><code>import * as bluebird from 'bluebird';
  
  export {bluebird as PType};
  </code></pre>
  
  <p>This works really well; however, augmenting interfaces only works if the .d.ts file doesn't export or import anything, so when I try to have <code>loginP</code> return <code>PType&lt;void&gt;</code>, the type it actually returns, the augmentation suddenly stops working:</p>
  
  <pre><code>import {PType} from '../lib/Promise';
  
  declare namespace Express {
      export interface Request {
          loginP(user: any): PType&lt;void&gt;;
      }
  }
  </code></pre>
  
  <p>(With the above code, the member <code>loginP</code> is not found anywhere on the interface).  If I remove the <code>import {PType}</code> line everything works fine -- except that I can't return the type I need.</p>
  
  <p>Any ideas? I'm using typescript 1.8.9 with a tsconfig file, building with <code>tsc -p .</code></p>