title: How to import a library in TypeScript when its type definitions do not declare a module?
body: <p>PeerJS has type definitions, but they are not exported as a module. They are declarations of types under some namespace.</p>
  
  <p>I am getting: <code>[ts] File 'c:/Users/Vincas/Desktop/language-exchange/node_modules/@types/peerjs/index.d.ts' is not a module.</code></p>
  
  <p>When trying to import it: <code>import Peer from 'peerjs'</code>
  This tries to import from type definitions, rather than the module itself, how do I import from a module here?</p>
  
  <p>The file from DefinitelyTyped is here: <a href="https://github.com/DefinitelyTyped/DefinitelyTyped/blob/354cec620daccfa0ad167ba046651fb5fef69e8a/types/peerjs/index.d.ts" rel="nofollow noreferrer">https://github.com/DefinitelyTyped/DefinitelyTyped/blob/354cec620daccfa0ad167ba046651fb5fef69e8a/types/peerjs/index.d.ts</a></p>
  
  <p>I've worked around for the time being like this:</p>
  
  <pre><code>const PeerJS: typeof Peer = require('peerjs')
  const peerjs = new PeerJS({ key: '**********' })
  </code></pre>
  
  <p>But this is so much inferior to: <code>import * as Peer from 'peerjs</code> or something similar... Is there no way to avoid defining global functions and global namespaces? That just looks like a terrible practice to me.</p>