title: How do you setup a require.js config with typescript?
body: <p>Ok, I've been reading a lot of questions and answers about this, and a lot of it is rubbish.</p>
  
  <p>I have a very simple question. How do I do the equivalent of this:</p>
  
  <pre><code>require.config({
      paths: {
          "blah": '/libs/blah/blah',
      }
  }); 
  require(['blah'], function(b) {
      console.log(b); 
  });
  </code></pre>
  
  <p>In typescript?</p>
  
  <p>This doesn't work:</p>
  
  <pre><code>declare var require;
  require.config({
      paths: {
          "blah": '/libs/blah/blah',
      }
  });
  import b = require('blah');
  console.log(b);
  
  s.ts(8,1): error TS2071: Unable to resolve external module ''blah''.
  s.ts(8,1): error TS2072: Module cannot be aliased to a non-module type.
  error TS5037: Cannot compile external modules unless the '--module' flag is provided.
  </code></pre>
  
  <p>Compiling with the --module flag, with a dummy blah.ts shim compiles, but the output is:</p>
  
  <pre><code>define(["require", "exports", 'blah'], function(require, exports, b) {
      require.config({
          paths: {
              "blah": '/libs/blah/blah'
          }
      });
  
      console.log(b);
  });
  </code></pre>
  
  <p>Looks like it might work, but actually no, the require.config is <em>inside</em> the require block, it is set <em>after</em> it is already needed.</p>
  
  <p>SO! I've ended up so far with <em>this</em> as a solution:</p>
  
  <pre><code>class RequireJS {
  
      private _r:any = window['require'];
  
      public config(config:any):void {
          this._r['config'](config);
      }
  
      public require(reqs:string[], callback:any):void {
          this._r(reqs, callback);
      }
  }
  
  var rjs = new RequireJS();
  rjs.config({
      paths: {
          "jquery": '/libs/jquery/jquery',
          "slider": '/js/blah/slider'
      }
  });
  
  rjs.require(['slider'], function(slider) {
      console.log(slider);
  });
  </code></pre>
  
  <p>Which seems terrible. </p>
  
  <p>So be clear, inside modules that depend on each other, this sort of thing works perfectly fine:</p>
  
  <pre><code>import $ = require('jquery');
  export module blah {
     ...
  }
  </code></pre>
  
  <p>I just need a proper way to setting the requirejs config at a top level, so that the imported paths for the various named modules are correct.</p>
  
  <p>(...and this is because, largely, 3rd party dependencies are resolved using bower, and installed in the /lib/blah, where as the shim files I have for their definitions are in src/deps/blah.d.ts, so the default import paths are incorrect after moving the generated modules files into /js/ on the site)</p>
  
  <p>NB. I've mentioned jquery here, but the problem is <em>not</em> that jquery doesn't work property as an AMD module; I have a shim jquery.ts.d file for this. The issue here is the requirejs paths.</p>