title: Can I use a custom module resolution function (like "proxyquire") in place of require() with TypeScript?
body: <p>I have a TypeScript file <code>config.ts</code> that will be run with node:</p>
  
  <pre><code>import myDependency = require('my-dependency');    
  
  export = {
      doSomething = () =&gt; {
          ...
      }
  }
  </code></pre>
  
  <p>In other TypeScript file, I can <code>import</code> this file with full type safety:</p>
  
  <pre><code>import config = require('./config');
  config.doSomething();
  config.doSomethingElse(); // compiler error, this method doesn't exist
  </code></pre>
  
  <p>Now I want to unit test this script. In order to mock out the dependencies that this script <code>require()</code>s I'm using <a href="https://github.com/thlorenz/proxyquire" rel="nofollow">proxyquire</a>, which lets me provide the values that my script will get when it makes calls to <code>require()</code>.  Here's what my test might look like:</p>
  
  <pre><code>import proxyquire = require('proxyquire');
  const config = proxyquire('./config', {
      'my-dependency': {} // this mocked object will be provided when config.ts asks for `my-dependency`
  });
  
  expect(config.doSomething()).to.do.something();
  </code></pre>
  
  <p>This works fine, except that my <code>config</code> variable is of type <code>any</code> because I'm using <code>proxyquire()</code> in place of <code>require()</code>.  TypeScript must give the <code>require()</code> function special treatment to allow it to perform module resolution.  Is there a way to tell the TypeScript compiler that <code>proxyquire()</code> should also do module resolution, similar to <code>require()</code>?</p>
  
  <p>I could rewrite <code>config.ts</code> as a class or make it use an interface. Then I would be able to explicitly type the variables in my tests by importing the class/interface definition.  But allowing <code>proxyquire()</code> to implicitly type things for me would be far be the easier solution.</p>