title: How do I export a single instance of a class and import that same instance in multiple files?
body: <p>I have a base file that contains a class:</p>
  
  <p>File-1:</p>
  
  <pre><code>class Foo {
     constructor() {
       this.count = 0;
     }
  }
  
  export = new Foo();
  </code></pre>
  
  <p>Then I import this instance in two other files:</p>
  
  <p>File-2:</p>
  
  <pre><code>import Foo = require("./File-1");
  Foo.count = 6;
  export const logFile2Count = () =&gt; console.log(Foo.count); // 6
  </code></pre>
  
  <p>File-3:</p>
  
  <pre><code>import Foo = require("./File-1");
  export const logFile3Count = () =&gt; console.log(Foo.count); // 0
  </code></pre>
  
  <p>File-4:</p>
  
  <pre><code>import { logFile2Count } from "./File-2";
  import { logFile3Count } from "./File-3";
  
  logFile2Count(); // "6"
  logFile3Count(); // "0" (Expected 6)
  </code></pre>
  
  <p>I want the state of Foo to stay persistent throughout all files that it's imported in. I.e. I want to import a reference of Foo in each file as oppose to a copy of Foo in each file. How can I do this?</p>