title: How to write a definition file for commonjs module that exports function
body: <p>I want to use simple commonjs module in typescript, and here are 3 files</p>
  
  <p>original lib:</p>
  
  <pre><code>//commonjs-export-function.js
  module.exports = function() {
      return 'func';
  };
  </code></pre>
  
  <p>definition file:</p>
  
  <pre><code>//commonjs-export-function.d.ts
  declare function func(): string;
  export = func;
  </code></pre>
  
  <p>typescript program which use it:</p>
  
  <pre><code>//main.ts
  import { func } from './commonjs-function';
  
  console.log(func());
  </code></pre>
  
  <p>When I run tsc I get this error:</p>
  
  <pre><code>tsc main.ts &amp;&amp; node main.js
  main.ts(1,22): error TS2497: Module '"/Users/aleksandar/projects/typescript-playground/commonjs-function"' resolves to a non-module entity and cannot be imported using this construct.
  </code></pre>
  
  <p>here is also already answered question but it doesn't work with typescript 2.0</p>
  
  <p><a href="https://stackoverflow.com/questions/24029462/how-to-write-a-typescript-definition-file-for-a-node-module-that-exports-a-funct">How to write a typescript definition file for a node module that exports a function?</a></p>