title: No TypeScript errors when accessing undefined methods of a require-d class
body: <p>I'm starting with TypeScript on a Node.JS stack, and I've noticed that when using <code>require</code> to import classes, TypeScript doesn't have a compilation error when methods (or properties) aren't defined.</p>
  
  <p>The error I'm expecting is <code>TS2551: Property 'undefinedMethod' does not exist on type 'typeof MyClass'. Did you mean 'definedMethod'?</code>, but it compiles just fine.</p>
  
  <p>Then when I try and run <code>server.ts</code>, I get <code>TypeError: MyClass.undefinedMethod is not a function</code> as a regular JavaScript error.</p>
  
  <p>If I use the <code>import {MyClass} from './MyClass';</code> syntax to import classes (and also change <code>MyClass</code> to <code>export class MyClass</code>), then TypeScript correctly complains that <code>MyClass.undefinedMethod</code> isn't defined.</p>
  
  <p>I can't use the <code>import</code> syntax because I need to be able to include <code>MyClass</code> on both the browser client and my Node.JS server (see end for specifics).</p>
  
  <p><strong>How can I get TypeScript to show a compile error on code that accesses an undefined method of a class?</strong></p>
  
  <hr>
  
  <p>Here's the code I've tried:</p>
  
  <p><code>MyClass.ts</code> (just a basic class I want to use in both <code>script.ts</code> and <code>server.ts</code>):</p>
  
  <pre><code>class MyClass {
  
      static definedMethod () :void {
          console.log('defined');
      }
  
  }
  
  if (typeof module !== 'undefined') {
      module.exports = MyClass;
  }
  </code></pre>
  
  <p><code>server.ts</code>: (I only included the relevant parts about <code>MyClass</code>, there's some other stuff for <code>express</code>):</p>
  
  <pre><code>const MyClass = require('./MyClass');
  // import MyClass = require('./MyClass'); // TS2306: File '[PATH]/source/MyClass.ts' is not a module.
  // import {MyClass} from './MyClass'; // TS2306: File '[PATH]/source/MyClass.ts' is not a module.
  
  MyClass.definedMethod();
  MyClass.undefinedMethod(); // No compiliation error.
  </code></pre>
  
  <p><code>script.ts</code>:</p>
  
  <pre><code>/// &lt;reference path="../MyClass.ts" /&gt;
  
  MyClass.definedMethod();
  MyClass.undefinedMethod(); // Throws correctly TS2551: Property 'undefinedMethod' does not exist on type 'typeof MyClass'. Did you mean 'definedMethod'?
  </code></pre>
  
  <p><code>tsconfig.json</code>:</p>
  
  <pre><code>{
    "compilerOptions": {
      "outDir": "./dist",
      "module": "umd",
      "target": "es5",
      "moduleResolution": "node"
    },
    "include": [
      "source/**/*"
    ]
  }
  </code></pre>
  
  <p>I don't really know what <code>allowSyntheticDefaultImports</code> and <code>esModuleInterop</code> do, but I tried adding them to my <code>tsconfig.json</code>, and it still didn't work.</p>
  
  <p>Directory structure:</p>
  
  <ul>
  <li><code>[dist]</code></li>
  <li><code>[source]</code>
  
  <ul>
  <li><code>[public]</code>
  
  <ul>
  <li><code>script.ts</code></li>
  </ul></li>
  <li><code>MyClass.ts</code></li>
  <li><code>server.ts</code></li>
  </ul></li>
  <li><code>tsconfig.json</code></li>
  </ul>
  
  <hr>
  
  <p>Specifics on why I can't change <code>require</code> to <code>import</code>:</p>
  
  <p>If I use the <code>import</code> and <code>export</code> syntax, my <code>server.ts</code> works, but then I can't use <code>/// &lt;reference path=</code> on my <code>script.ts</code> because error <code>TS2304: Cannot find name 'MyClass'.</code></p>
  
  <p>If I just change to use <code>import</code> in <code>server.ts</code>, I get <code>TS2306: File '[PATH]/source/MyClass.ts' is not a module.</code></p>