title: How to import a TypeScript module definition for a global third-party library
body: <p>I am using a third-party Javascript library that has to be imported directly via a <code>&lt;script&gt;</code> tag in my index.html file. As the library is in my <code>public/</code> folder, Typescript (v3.8.3) is able to find it.</p>
  
  <p>The library looks like this:</p>
  
  <pre><code>var MyLib = {x: ..., y: ... z:...}
  MyLib.SomeFunc = ...
  MyLib.SomeOtherFunc = ...
  </code></pre>
  
  <p>When I use <code>MyLib</code> in my Typescript project (as a global, no <code>import</code> statement), Typescript recognizes MyLib as having the properties <code>X, Y Z</code>, but not <code>SomeFunc</code> and <code>SomeOtherFunc</code>.</p>
  
  <p>To fix this, there exists a typings file, <code>mylib.d.ts</code>.</p>
  
  <p>It looks like this:</p>
  
  <pre><code>export = MyLib;
  
  declare module MyLib {
    function SomeFunc ...;
    ...
  }
  </code></pre>
  
  <p>I added <code>mylib.d.ts</code> to my src root, where my other <code>*.d.ts</code> files are.</p>
  
  <p>However, Typescript does <strong>not</strong> pick this up. It sticks to the inferences it has made by reading the <code>MyLib.js</code> file directly.</p>
  
  <p>How can I get Typescript to read these definitions?</p>
  
  <p><strong>What I have tried:</strong></p>
  
  <ul>
  <li><code>/// &lt;reference types="../myLib"</code>. Typescript still uses the auto-generated types from the actual <code>myLib.js</code> file</li>
  <li><code>import "../myLib";</code>. Doesn't work because it's just a typing file, not a module.</li>
  <li><code>import type MyLib from "../myLib";</code>. This seems to not be valid Typescript yet, although it seemed like it was going to be in v3.8. I'm not sure if that's correct anyway, because MyLib is a namespace, not a type.</li>
  </ul>