title: Require.js singleton to TypeScript
body: <p>Here are two watered down example files. This is currently how they work as requirejs modules. I've shimmed api.js in my require config to define the export as API. The goal is that these will stay as singletons. I'm trying to convert them to TypeScript equivalents but can't quite figure out how to keep them as a singleton and pass them around to various modules like I do now.</p>
  
  <p><strong>RequireJS style</strong></p>
  
  <p><em>api.js</em></p>
  
  <pre><code>(function (global) {
  
      var API = global.API = {};
      API.version = '0.0.1';
      API.env = 'local';
      API.header = '';
  
  } (this));
  </code></pre>
  
  <p><em>auth.js</em></p>
  
  <pre><code>define([
      'api',
  ], function (api) {
          'use strict';
  
          CommonAuth = {
  
              maxExpiredAuthorizationRetries: 1,
  
              getAuthorizationHeader: function () {
                  return api.header;
              },
  
              setAuthorizationHeader: function (val) {
                  api.header = val;
              }
  
          };
  
          return CommonAuth;
  
      }
  );
  </code></pre>
  
  <p><strong>TypeScript/AMD(requirejs) style</strong></p>
  
  <p>I've got the following so far but this is obviously not what I am after.</p>
  
  <p><em>auth.ts</em></p>
  
  <pre><code>// don't know how to fake this without creating a valid api module. requirejs shim is what handles my export
  import api = module("api");
  
  export module Common {
  
      class Auth {
  
          public maxExpiredAuthorizationRetries: number;
  
          constructor (maxExpiredAuthorizationRetries: number) {
              this.maxExpiredAuthorizationRetries = maxExpiredAuthorizationRetries;
          }
  
          public getAuthorizationHeader(): string {
              return api.header();
          }
  
          public setAuthorizationHeader(val: string): void {
              api.header(val);
          }
      }
  
      var auth = new Auth(1);
  }
  </code></pre>
  
  <p>which compiles to <em>auth.js</em> (<code>tsc auth.ts --module amd</code>)</p>
  
  <pre><code>define(["require", "exports", "api"], function(require, exports, __api__) {
      var api = __api__;
  
      (function (Common) {
          var Auth = (function () {
              function Auth(maxExpiredAuthorizationRetries) {
                  this.maxExpiredAuthorizationRetries = maxExpiredAuthorizationRetries;
              }
              Auth.prototype.getAuthorizationHeader = function () {
                  return api.header();
              };
              Auth.prototype.setAuthorizationHeader = function (val) {
                  api.header(val);
              };
              return Auth;
          })();        
          var auth = new Auth(1);
      })(exports.Common || (exports.Common = {}));
  
  })
  </code></pre>
  
  <p><strong>Update:</strong> in addition to the accepted answer you can directly export all members:</p>
  
  <pre><code>export var maxExpiredAuthorizationRetries: number = 1;
  export function getAuthorizationHeader(): string { ...
  export function setAuthorizationHeader(val: string): string {
  </code></pre>
  
  <p>and then <code>import api = module('api');</code> can be used simply by saying <code>api.getAuthorizationHeader()</code>.</p>