title: Can I import *.d.ts instead of require it?
body: <p>I have some module <code>lib</code> in <code>node_modules</code> and I want to use it.
  I wrote <code>lib.d.ts</code> for this.</p>
  
  <p>Files looks like:</p>
  
  <pre><code>/src/
      main.ts (imports `lib`)
  /types/
      lib.d.ts
  </code></pre>
  
  <p>In file <code>main.ts</code> I can write this code:</p>
  
  <pre><code>/// &lt;reference path="../types/lib.d.ts" /&gt;
  import {some} from 'lib';
  </code></pre>
  
  <p>And it works.</p>
  
  <p>But when I try to use import for ambient declaration file:</p>
  
  <pre><code>import '../types/lib';
  import {some} from 'lib';
  </code></pre>
  
  <p>it compiles without errors, but in resulting JS I can find require for this file:</p>
  
  <pre><code>require('../types/lib');
  const lib_1 = require('lib');
  </code></pre>
  
  <p>With error in runtime of missing file <code>../types/lib</code> –
  it's just an ambient declaration file without resulting file.</p>
  
  <p>Why compiler did not remove import of *.d.ts file?<br>
  Can I use import somehow, or I must use reference instead?</p>
  
  <p><strong>Solution:</strong></p>
  
  <p>If you don't want to use <code>reference</code> directives,
  you can just add required *.d.ts to files,
  included by your tsconfig.json.</p>
  
  <p>My tsconfig.json was:</p>
  
  <pre><code>{
      "compilerOptions": {
          "module": "commonjs",
          "target": "es2015",
          "lib": ["es2016"],
          "noImplicitAny": true,
          "noImplicitReturns": true,
          "noImplicitThis": true,
          "strictNullChecks": true,
          "noFallthroughCasesInSwitch": true,
          "noUnusedLocals": true,
          "noUnusedParameters": true,
          "noEmitOnError": true,
          "newLine": "LF",
          "forceConsistentCasingInFileNames": true,
          "removeComments": true,
          "declaration": false,
          "sourceMap": false,
          "outDir": "../build",
          "types": [
              "node"
          ]
      },
      "files": [
          "index.ts"
      ]
  }
  </code></pre>
  
  <p>Early I tried to add my .d.ts to <code>types</code> section, but in this case
  tcs is trying to find this file in node_modules/@types directory.</p>
  
  <p>After suggestion I tried to add file in <code>files</code> section:</p>
  
  <pre><code>    "files": [
          "index.ts",
          "types/lib.d.ts"
      ]
  </code></pre>
  
  <p>It's works and seems as a good solution.</p>