How to use external library in a Typescript 2.0 project?
<p>I have a Typescript 2.0 project that uses Common JS modules and System JS loader.  I use Visual Studio code as IDE.  I am having trouble using an external library (filesaver JS) in my project.  </p>

<p>I installed both the <a href="https://github.com/eligrey/FileSaver.js/blob/master/FileSaver.js" rel="nofollow">library</a> and the <a href="https://github.com/DefinitelyTyped/DefinitelyTyped/blob/types-2.0/filesaver/index.d.ts" rel="nofollow">type definition</a> via npm.  Both appear in my node_modules and node_module/@types respectively.</p>

<p>How do I reference (import) the filesaver saveAs function in my TypeScript code in my function that is to save a blob (an object converted to a JSON string)?</p>

<p>I tried several variations of import, but none of them seems to work for me.  I get either 'index.d.ts' is not a module error, or 'module not found' error. </p>

<p>Here is what I tried:</p>

<p><code>import filesaver = require('FileSaver');  //error: index.d.ts is not a module
import {FileSaver} from 'file-saver';  //error: cannot find module file-saver</code></p>

<p><strong>tsconfig.json</strong></p>

<pre><code>{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "declaration": false,
    "removeComments": true,
    "noLib": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": ["es6", "es2015", "dom"],
    "sourceMap": true,
    "pretty": true,
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitUseStrict": false,
    "noFallthroughCasesInSwitch": true,
    "typeRoots": [
      "./node_modules/@types",
      "./node_modules"
    ],
    "types": [
      "node"
    ]
  },
  "exclude": [
    "node_modules",
    "dist",
    "src"
  ],
  "compileOnSave": false
}
</code></pre>