title: How to import KnockOut 4 in TypeScript?
body: <p>This seems simple because the same code works well in simple JS file and it also has autocompletion for the ko variable's members. I have the following TypeScript code below:</p>
  
  <pre class="lang-js prettyprint-override"><code>// both of the following import lines result in: `ko` undefined
  
  // import { ko } from "@tko/build.knockout";
  import { ko } from "../node_modules/@tko/build.knockout/dist/build.knockout.es6";
  
  
  alert("test: " + ko);
  </code></pre>
  
  <h1><code>tsconfig.json</code></h1>
  
  <pre><code>{
      "compilerOptions": {
          "removeComments": true,
          "preserveConstEnums": true,
          "sourceMap": true,
          "outDir": "js",
          "target": "ES3",
          "watch": true,
          "allowJs": true,
          "lib": ["ES5", "DOM"],
          "module": "CommonJS"
      },
      "include": [
          "ts"
      ],
      "exclude": [
          "node_modules"
      ]
  }
  </code></pre>
  
  <p>The test repo is <a href="https://github.com/silviubogan/ko4-typescript-test" rel="nofollow noreferrer">here</a>.</p>
  
  <blockquote>
    <p>Using the given tsconfig.json file, I cannot import the ko4 package well. I could change some of the things in tsconfig.json but I do not know how to make it compatible with all the used modules in my main project. I chose to use ES6 import syntax because it is future-proof.</p>
  </blockquote>
  
  <p>I would have used KnockOut v3.5 but it does not work with ES6 import syntax.</p>
  
  <p>I also wish to mention that I use VS Code.</p>
  
  <p>Thank you.</p>
  
  <h1>Update 1</h1>
  
  <p><em>(based on the answer from Nenad</em>)</p>
  
  <p>In tsconfig.json I had to set moduleResolution to "Node" (previously it was the default, in my case "classic").</p>
  
  <p>I also had to create a <code>package.json</code> file in the root directory of my project. I thought I had one, but I had just a <code>package-lock.json</code>. After creating the <code>package.json</code> file, I rerun <code>npm i</code> and now VS Code understands the imports. I do not have to put a path to something inside the <code>node_modules</code> directory, I just put the name of the npm module.</p>
  
  <p>I also had to replace <code>KnockoutObservable</code> with <code>ko.Observable</code> and all the other <code>Knockout...</code>-named classes and interfaces used in my project.</p>
  
  <p>The remaining problem is that after I switched to the AMD module system the output file (bundle.js) does not contain all the needed modules, just the main.ts file converted to JS. Probably this is the subject of another question.</p>