<p dir="auto">Example:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class Component {
    static all : Array&lt;typeof Component&gt;
    static constructor() {
        Component.all.push( this )
    }
}

class MyButton extends {}
class MyCheckbox extends {}
class MyRadio extends {}

console.assert( Component.all[0] === MyButton , 'registration MyButton' )
console.assert( Component.all[1] === MyCheckbox , 'registration MyChackbox' )
console.assert( Component.all[2] === MyRadio , 'registration MyRadio' )"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-smi">Component</span> <span class="pl-kos">{</span>
    <span class="pl-k">static</span> <span class="pl-c1">all</span> : <span class="pl-smi">Array</span><span class="pl-kos">&lt;</span><span class="pl-k">typeof</span> <span class="pl-smi">Component</span><span class="pl-kos">&gt;</span>
    <span class="pl-k">static</span> <span class="pl-en">constructor</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-smi">Component</span><span class="pl-kos">.</span><span class="pl-c1">all</span><span class="pl-kos">.</span><span class="pl-en">push</span><span class="pl-kos">(</span> <span class="pl-smi">this</span> <span class="pl-kos">)</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-k">class</span> <span class="pl-smi">MyButton</span> <span class="pl-k">extends</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>
<span class="pl-k">class</span> <span class="pl-smi">MyCheckbox</span> <span class="pl-k">extends</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>
<span class="pl-k">class</span> <span class="pl-smi">MyRadio</span> <span class="pl-k">extends</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>

<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">assert</span><span class="pl-kos">(</span> <span class="pl-smi">Component</span><span class="pl-kos">.</span><span class="pl-c1">all</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span> <span class="pl-c1">===</span> <span class="pl-smi">MyButton</span> <span class="pl-kos">,</span> <span class="pl-s">'registration MyButton'</span> <span class="pl-kos">)</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">assert</span><span class="pl-kos">(</span> <span class="pl-smi">Component</span><span class="pl-kos">.</span><span class="pl-c1">all</span><span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">]</span> <span class="pl-c1">===</span> <span class="pl-smi">MyCheckbox</span> <span class="pl-kos">,</span> <span class="pl-s">'registration MyChackbox'</span> <span class="pl-kos">)</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">assert</span><span class="pl-kos">(</span> <span class="pl-smi">Component</span><span class="pl-kos">.</span><span class="pl-c1">all</span><span class="pl-kos">[</span><span class="pl-c1">2</span><span class="pl-kos">]</span> <span class="pl-c1">===</span> <span class="pl-smi">MyRadio</span> <span class="pl-kos">,</span> <span class="pl-s">'registration MyRadio'</span> <span class="pl-kos">)</span></pre></div>
<p dir="auto">This not works. But we have workaround:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="/// Support for static constructors
var __extends = ( Sub , Sup ) =&gt; {
    for( var prop in Sup ) if( Sup.hasOwnProperty( prop ) ) Sub[ prop ] = Sup[ prop ]
    Sub.prototype = Object.create( Sup.prototype )
    Sub.prototype.constructor = Sub
    if( Sub.initializer ) Sub.initializer()
};

class Component {
    static all : Array&lt;typeof Component&gt; = []
    static initializer() {
        Component.all.push( this )
    }
}

class MyButton extends Component {}
class MyCheckbox extends Component {}
class MyRadio extends Component {}

console.assert( Component.all[0] === MyButton , 'registration MyButton' )
console.assert( Component.all[1] === MyCheckbox , 'registration MyChackbox' )
console.assert( Component.all[2] === MyRadio , 'registration MyRadio' )"><pre class="notranslate"><span class="pl-c">/// Support for static constructors</span>
<span class="pl-k">var</span> <span class="pl-en">__extends</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span> <span class="pl-smi">Sub</span> <span class="pl-kos">,</span> <span class="pl-smi">Sup</span> <span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">for</span><span class="pl-kos">(</span> <span class="pl-k">var</span> <span class="pl-s1">prop</span> <span class="pl-k">in</span> <span class="pl-smi">Sup</span> <span class="pl-kos">)</span> <span class="pl-k">if</span><span class="pl-kos">(</span> <span class="pl-smi">Sup</span><span class="pl-kos">.</span><span class="pl-en">hasOwnProperty</span><span class="pl-kos">(</span> <span class="pl-s1">prop</span> <span class="pl-kos">)</span> <span class="pl-kos">)</span> <span class="pl-smi">Sub</span><span class="pl-kos">[</span> <span class="pl-s1">prop</span> <span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-smi">Sup</span><span class="pl-kos">[</span> <span class="pl-s1">prop</span> <span class="pl-kos">]</span>
    <span class="pl-smi">Sub</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span> <span class="pl-c1">=</span> <span class="pl-smi">Object</span><span class="pl-kos">.</span><span class="pl-en">create</span><span class="pl-kos">(</span> <span class="pl-smi">Sup</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span> <span class="pl-kos">)</span>
    <span class="pl-smi">Sub</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">.</span><span class="pl-c1">constructor</span> <span class="pl-c1">=</span> <span class="pl-smi">Sub</span>
    <span class="pl-k">if</span><span class="pl-kos">(</span> <span class="pl-smi">Sub</span><span class="pl-kos">.</span><span class="pl-c1">initializer</span> <span class="pl-kos">)</span> <span class="pl-smi">Sub</span><span class="pl-kos">.</span><span class="pl-en">initializer</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span>

<span class="pl-k">class</span> <span class="pl-smi">Component</span> <span class="pl-kos">{</span>
    <span class="pl-k">static</span> <span class="pl-c1">all</span> : <span class="pl-smi">Array</span><span class="pl-kos">&lt;</span><span class="pl-k">typeof</span> <span class="pl-smi">Component</span><span class="pl-kos">&gt;</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-kos">]</span>
    <span class="pl-k">static</span> <span class="pl-en">initializer</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-smi">Component</span><span class="pl-kos">.</span><span class="pl-c1">all</span><span class="pl-kos">.</span><span class="pl-en">push</span><span class="pl-kos">(</span> <span class="pl-smi">this</span> <span class="pl-kos">)</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-k">class</span> <span class="pl-smi">MyButton</span> <span class="pl-k">extends</span> <span class="pl-smi">Component</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>
<span class="pl-k">class</span> <span class="pl-smi">MyCheckbox</span> <span class="pl-k">extends</span> <span class="pl-smi">Component</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>
<span class="pl-k">class</span> <span class="pl-smi">MyRadio</span> <span class="pl-k">extends</span> <span class="pl-smi">Component</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>

<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">assert</span><span class="pl-kos">(</span> <span class="pl-smi">Component</span><span class="pl-kos">.</span><span class="pl-c1">all</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span> <span class="pl-c1">===</span> <span class="pl-smi">MyButton</span> <span class="pl-kos">,</span> <span class="pl-s">'registration MyButton'</span> <span class="pl-kos">)</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">assert</span><span class="pl-kos">(</span> <span class="pl-smi">Component</span><span class="pl-kos">.</span><span class="pl-c1">all</span><span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">]</span> <span class="pl-c1">===</span> <span class="pl-smi">MyCheckbox</span> <span class="pl-kos">,</span> <span class="pl-s">'registration MyChackbox'</span> <span class="pl-kos">)</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">assert</span><span class="pl-kos">(</span> <span class="pl-smi">Component</span><span class="pl-kos">.</span><span class="pl-c1">all</span><span class="pl-kos">[</span><span class="pl-c1">2</span><span class="pl-kos">]</span> <span class="pl-c1">===</span> <span class="pl-smi">MyRadio</span> <span class="pl-kos">,</span> <span class="pl-s">'registration MyRadio'</span> <span class="pl-kos">)</span></pre></div>
<p dir="auto">But:</p>
<ul dir="auto">
<li>This is hack.</li>
<li><code class="notranslate">initializer</code> calls only on descendant classes.</li>
</ul>
<p dir="auto">We can use decorators:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class Component {
    static all : Array&lt;typeof Component&gt; = []
    static register( comp : typeof Component ) {
        Component.all.push( comp )
    }
}

@ Component.register
class MyButton extends Component {}

@ Component.register
class MyCheckbox extends Component {}

@ Component.register
class MyRadio extends Component {}

console.assert( Component.all[0] === MyButton , 'registration MyButton' )
console.assert( Component.all[1] === MyCheckbox , 'registration MyChackbox' )
console.assert( Component.all[2] === MyRadio , 'registration MyRadio' )"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-smi">Component</span> <span class="pl-kos">{</span>
    <span class="pl-k">static</span> <span class="pl-c1">all</span> : <span class="pl-smi">Array</span><span class="pl-kos">&lt;</span><span class="pl-k">typeof</span> <span class="pl-smi">Component</span><span class="pl-kos">&gt;</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-kos">]</span>
    <span class="pl-k">static</span> <span class="pl-en">register</span><span class="pl-kos">(</span> <span class="pl-s1">comp</span> : <span class="pl-k">typeof</span> <span class="pl-smi">Component</span> <span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-smi">Component</span><span class="pl-kos">.</span><span class="pl-c1">all</span><span class="pl-kos">.</span><span class="pl-en">push</span><span class="pl-kos">(</span> <span class="pl-s1">comp</span> <span class="pl-kos">)</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

@ <span class="pl-smi">Component</span><span class="pl-kos">.</span><span class="pl-c1">register</span>
<span class="pl-k">class</span> <span class="pl-smi">MyButton</span> <span class="pl-k">extends</span> <span class="pl-smi">Component</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>

@ <span class="pl-smi">Component</span><span class="pl-kos">.</span><span class="pl-c1">register</span>
<span class="pl-k">class</span> <span class="pl-smi">MyCheckbox</span> <span class="pl-k">extends</span> <span class="pl-smi">Component</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>

@ <span class="pl-smi">Component</span><span class="pl-kos">.</span><span class="pl-c1">register</span>
<span class="pl-k">class</span> <span class="pl-smi">MyRadio</span> <span class="pl-k">extends</span> <span class="pl-smi">Component</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>

<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">assert</span><span class="pl-kos">(</span> <span class="pl-smi">Component</span><span class="pl-kos">.</span><span class="pl-c1">all</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span> <span class="pl-c1">===</span> <span class="pl-smi">MyButton</span> <span class="pl-kos">,</span> <span class="pl-s">'registration MyButton'</span> <span class="pl-kos">)</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">assert</span><span class="pl-kos">(</span> <span class="pl-smi">Component</span><span class="pl-kos">.</span><span class="pl-c1">all</span><span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">]</span> <span class="pl-c1">===</span> <span class="pl-smi">MyCheckbox</span> <span class="pl-kos">,</span> <span class="pl-s">'registration MyChackbox'</span> <span class="pl-kos">)</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">assert</span><span class="pl-kos">(</span> <span class="pl-smi">Component</span><span class="pl-kos">.</span><span class="pl-c1">all</span><span class="pl-kos">[</span><span class="pl-c1">2</span><span class="pl-kos">]</span> <span class="pl-c1">===</span> <span class="pl-smi">MyRadio</span> <span class="pl-kos">,</span> <span class="pl-s">'registration MyRadio'</span> <span class="pl-kos">)</span></pre></div>
<p dir="auto">But:</p>
<ul dir="auto">
<li>Too more code.</li>
<li>User may forget to register component and don't understand why his code not works.</li>
</ul>
<p dir="auto">A <strong>static constructor</strong> is a function that is run only once when the class is loaded. It can be used to initialize static class members and maybe as entry point to the application.</p>
<p dir="auto">Suggested syntax is:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class MyClass {
    static initialized = false;

    static constructor() {
        MyClass.initialized = true;
    }
}

alert(MyClass.initialized);"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-smi">MyClass</span> <span class="pl-kos">{</span>
    <span class="pl-k">static</span> <span class="pl-c1">initialized</span> <span class="pl-c1">=</span> <span class="pl-c1">false</span><span class="pl-kos">;</span>

    <span class="pl-k">static</span> <span class="pl-en">constructor</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-smi">MyClass</span><span class="pl-kos">.</span><span class="pl-c1">initialized</span> <span class="pl-c1">=</span> <span class="pl-c1">true</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-en">alert</span><span class="pl-kos">(</span><span class="pl-smi">MyClass</span><span class="pl-kos">.</span><span class="pl-c1">initialized</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">That would be same as the following:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class MyClass {
    static initialized = false;

    static __ctor = (() =&gt; {
        MyClass.initialized = true;
    })();
}

alert(MyClass.initialized);"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-smi">MyClass</span> <span class="pl-kos">{</span>
    <span class="pl-k">static</span> <span class="pl-c1">initialized</span> <span class="pl-c1">=</span> <span class="pl-c1">false</span><span class="pl-kos">;</span>

    <span class="pl-k">static</span> <span class="pl-c1">__ctor</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
        <span class="pl-smi">MyClass</span><span class="pl-kos">.</span><span class="pl-c1">initialized</span> <span class="pl-c1">=</span> <span class="pl-c1">true</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-en">alert</span><span class="pl-kos">(</span><span class="pl-smi">MyClass</span><span class="pl-kos">.</span><span class="pl-c1">initialized</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Except that <code class="notranslate">__ctor</code> does not need to be assigned to the class in the output code, and only needs to be invoked in an anonymous function. Also compiler can check that no more than one static constructor is defined in a class.</p>
<p dir="auto"><strong>Update:</strong> Since this generates an Immediately-Invoked Function Expression (IIFE), compiler should make sure to move it to the end of the class definition in the output JavaScript.</p>
<p dir="auto">TypeScript:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class MyClass {
    static constructor() {
        MyClass.initialized = true;
    }

    static initialized = false;
}"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-smi">MyClass</span> <span class="pl-kos">{</span>
    <span class="pl-k">static</span> <span class="pl-en">constructor</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-smi">MyClass</span><span class="pl-kos">.</span><span class="pl-c1">initialized</span> <span class="pl-c1">=</span> <span class="pl-c1">true</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>

    <span class="pl-k">static</span> <span class="pl-c1">initialized</span> <span class="pl-c1">=</span> <span class="pl-c1">false</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Expected JavaScript output:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var MyClass = (function () {
    function MyClass() {
    }
    MyClass.initialized = false;

    // run last
    (function () {
        MyClass.initialized = true;
    })();
    return MyClass;
})();"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-v">MyClass</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">function</span> <span class="pl-v">MyClass</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-kos">}</span>
    <span class="pl-v">MyClass</span><span class="pl-kos">.</span><span class="pl-c1">initialized</span> <span class="pl-c1">=</span> <span class="pl-c1">false</span><span class="pl-kos">;</span>

    <span class="pl-c">// run last</span>
    <span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-v">MyClass</span><span class="pl-kos">.</span><span class="pl-c1">initialized</span> <span class="pl-c1">=</span> <span class="pl-c1">true</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">return</span> <span class="pl-v">MyClass</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Note that body of the static constructor is moved to the bottom and invoked.</p>
<blockquote>
<p dir="auto">Related suggestion in codeplex: <a href="https://typescript.codeplex.com/workitem/862" rel="nofollow">Please add static constructors to classes</a></p>
</blockquote>