<p dir="auto">The <a href="http://wiki.ecmascript.org/doku.php?id=strawman:maximally_minimal_classes" rel="nofollow">ES6 definition of the "class" construct</a> has the concept of "class expression" - i.e. class definitions may be used as values, such as:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="var obj = new (class { x = 5; });
var cls = class { x = 5; };
var cls2 = class extends cls { y = 6; };
var obj2 = new cls2();
// and so on"><pre class="notranslate"><code class="notranslate">var obj = new (class { x = 5; });
var cls = class { x = 5; };
var cls2 = class extends cls { y = 6; };
var obj2 = new cls2();
// and so on
</code></pre></div>
<p dir="auto">Sadly, this support is absent in the current TypeScript compiler (I'm using the 9.2 branch) - that is, the above examples would not compile.</p>
<p dir="auto">Aside from TS team's own argument of "closely aligning with the ES6 specification", this support would enable many useful scenarios for which I currently have to fall back to "any-typed" plain JavaScript.</p>
<p dir="auto">Here are a few examples of such scenarios which I actually use in my daily work:</p>
<ol dir="auto">
<li>Returning a class (not object) from a function. With TypeScript, it is currently possible to describe the return type of such function, but not to actually write its body using the "class" construct.</li>
<li>"Bind" a class - similar to "binding" a function, i.e. produce another class with certain constructor parameters bound to specific values.</li>
<li>Declare a "private" class within the body of a function or within another class.</li>
</ol>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="module foobar
{
   export function foo()
   {
      return;
   }

   export enum foo
   {
      bar,
      baz
   }
} "><pre class="notranslate">module <span class="pl-s1">foobar</span>
<span class="pl-kos">{</span>
   <span class="pl-k">export</span> <span class="pl-k">function</span> <span class="pl-en">foo</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-kos">;</span>
   <span class="pl-kos">}</span>

   <span class="pl-k">export</span> <span class="pl-k">enum</span> <span class="pl-s1">foo</span>
   <span class="pl-kos">{</span>
      <span class="pl-c1">bar</span><span class="pl-kos">,</span>
      <span class="pl-c1">baz</span>
   <span class="pl-kos">}</span>
<span class="pl-kos">}</span> </pre></div>
<p dir="auto">results in valid javascript:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var foobar;
(function (foobar) {
    function foo() {
        return;
    }
    foobar.foo = foo;

    (function (foo) {
        foo[foo[&quot;bar&quot;] = 0] = &quot;bar&quot;;
        foo[foo[&quot;baz&quot;] = 1] = &quot;baz&quot;;
    })(foobar.foo || (foobar.foo = {}));
    var foo = foobar.foo;
})(foobar || (foobar = {}));"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">foobar</span><span class="pl-kos">;</span>
<span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">foobar</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">function</span> <span class="pl-en">foo</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-kos">;</span>
    <span class="pl-kos">}</span>
    <span class="pl-s1">foobar</span><span class="pl-kos">.</span><span class="pl-c1">foo</span> <span class="pl-c1">=</span> <span class="pl-s1">foo</span><span class="pl-kos">;</span>

    <span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">foo</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-s1">foo</span><span class="pl-kos">[</span><span class="pl-s1">foo</span><span class="pl-kos">[</span><span class="pl-s">"bar"</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-s">"bar"</span><span class="pl-kos">;</span>
        <span class="pl-s1">foo</span><span class="pl-kos">[</span><span class="pl-s1">foo</span><span class="pl-kos">[</span><span class="pl-s">"baz"</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-s">"baz"</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-s1">foobar</span><span class="pl-kos">.</span><span class="pl-c1">foo</span> <span class="pl-c1">||</span> <span class="pl-kos">(</span><span class="pl-s1">foobar</span><span class="pl-kos">.</span><span class="pl-c1">foo</span> <span class="pl-c1">=</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">var</span> <span class="pl-s1">foo</span> <span class="pl-c1">=</span> <span class="pl-s1">foobar</span><span class="pl-kos">.</span><span class="pl-c1">foo</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-s1">foobar</span> <span class="pl-c1">||</span> <span class="pl-kos">(</span><span class="pl-s1">foobar</span> <span class="pl-c1">=</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">...and even shows proper code hinting/completion in Visual Studio.</p>
<p dir="auto">Yet it doesn't compile due to a duplicate identifier error: <code class="notranslate">Error  2   Duplicate identifier 'foo'</code></p>
<p dir="auto">Seeing as both the resulting JS and IDE support are already functioning, why is this a syntax error to tsc?</p>