title: Importing Static Functions Typescript
body: <p>I am trying to import a static class function into my main.js file but using the function after compiling with tsc I get:</p>
  <blockquote>
  <p>TypeError: Cannot read property 'router' of undefined
  at Object. (path/to/main.js:36:27)&gt;</p>
  </blockquote>
  <p>I have tried to assign it a type with no luck as well as using different methods of importing again with no luck...</p>
  <p>I feel as if the answer is simple but cant seem to locate it in the TS docs and I'm just banging my head at this point.</p>
  <p>Here is the class I am trying to export.</p>
  <blockquote>
  <p>Session.ts</p>
  </blockquote>
  <pre><code>export class Session {
  
      //Class Members
  
     constructor() {
        //Big constructor lots of this. = 
     };
  
     //Creating the functions needed
  
     logOut() {
        delete Session.ssnsById[this.id];
        delete Session.ssnsByCookie[this.authToken];
     };
  
  static router = function (req: Request, res: Response, next: Function) {
        var cookie = req.cookies[Session.cookieName];
        var session = cookie &amp;&amp; Session.ssnsByCookie[cookie];
  
        if (session) {
           // If the session was last used more than |duration| mS ago..
           if (session.lastUsed &lt; new Date().getTime() - Session.duration)
              session.logOut();
           else {
              req.session = session;
           }
        }
        next();
     };
  }
  
  module.exports = Session;
  
  </code></pre>
  <blockquote>
  <p>Importing into my main.ts</p>
  </blockquote>
  <pre><code>import { Session } from &quot;./Session&quot;;
  
  
  // Set up Session on req if available
  app.use(Session.router); //&lt;--
  </code></pre>
  <p>After running tsc we get built/main.js</p>
  <pre><code>const Session_1 = require(&quot;./Session&quot;);
  
  // Set up Session on req if available
  app.use(Session_1.Session.router); //&lt;-This line throws the error.
  </code></pre>
  <p>Lastly here is my tsconfig.json used to compile</p>
  <pre><code>{
     &quot;compilerOptions&quot;: {
         &quot;module&quot;: &quot;commonjs&quot;,
         &quot;esModuleInterop&quot;: true,
         &quot;target&quot;: &quot;es6&quot;,
         &quot;noImplicitAny&quot;: true,
         &quot;noImplicitThis&quot;: true,
         &quot;moduleResolution&quot;: &quot;node&quot;,
         &quot;sourceMap&quot;: false,
         &quot;baseUrl&quot;: &quot;.&quot;,
         &quot;outDir&quot;: &quot;built&quot;,
         &quot;paths&quot;: {
             &quot;*&quot;: [
                 &quot;node_modules/*&quot;
             ]
         }
     },
     &quot;include&quot;: [
         &quot;Src/**/*&quot;
     ]
  }
  </code></pre>