title: Can Typescript import CommonJS Modules?
body: <p>I had this file:</p>
  
  <pre><code>//foo.js
  var foo = function () {
      return "foo";
  }; 
  
  module.exports = foo;
  </code></pre>
  
  <p>So, I wanted to import it to my Typescript file. I tried this</p>
  
  <pre><code>//typescript.ts
  import * as foo from ("./foo");
  </code></pre>
  
  <p>Didn't work. I read about this 'ambient' modules, so I added this</p>
  
  <pre><code>//typescript.ts
  /// &lt;reference path="./foo.d.ts" /&gt;
  import * as foo from ("./foo");
  </code></pre>
  
  <p>And I added a "foo.d.ts" file in the same folder, which had the purpose of letting typescript know about the types of my imported function:</p>
  
  <pre><code>declare module "foo" 
  {
      function foo(): string
      export = foo;
  }
  </code></pre>
  
  <p>No luck.</p>
  
  <p>I thought that the problem was with the import syntax (you cannot have the same syntax for es6 and commonjs modules, right?). So I did this.</p>
  
  <pre><code>import foo = require("./foo");
  </code></pre>
  
  <p>As you might guess, that didn't work either. </p>
  
  <p>I have been able to import d3 an use it successfully when I installed it as a node module with <code>npm install d3</code> and referenced its <code>d.ts</code> file. I did it with this code:</p>
  
  <pre><code>import * as d3 from "d3";
  </code></pre>
  
  <p>I haven't been able to do the same with any other module (jquery, box2d, box2d-commonjs, among others), nor with my own libraries as demonstrated above. I am new to Typescript, so probably I'm missing something very obvious, but I haven't been able to figure it out by myself. </p>