title: TypeScript: Global static variable best practice
body: <p>I have this class where I need to increment a number each time the class is instantiated.
  I have found two ways to this where both ways works, but I am not sure yet on what is the best practice</p>
  
  <ol>
  <li><p>declare the variable in the module scope</p>
  
  <pre><code>module M {
    var count : number = 0;
    export class C {
      constructor() {
        count++;
      }
    }
  }
  </code></pre></li>
  <li><p>declare the variable in the class scope and access it on Class</p>
  
  <pre><code>module M {
    export class C {
      static count : number = 0;
      constructor() {
        C.count++;  
      }
    }
  }
  </code></pre></li>
  </ol>
  
  <p>My take is example two as it does not adds the count variable in the module scope.</p>
  
  <p>See also: <a href="https://stackoverflow.com/questions/8132413/c-sharp-incrementing-static-variables-upon-instantiation">C# incrementing static variables upon instantiation</a></p>