<p dir="auto">The problem I found can be reproduced with the <a href="http://www.typescriptlang.org/Playground#src=function%20builder%28%29%20%7B%0D%0A%09return%20new%20class%20House%20%7B%0D%0A%09%09public%20open%28%29%3Avoid%20%7B%0D%0A%09%09%09console.info%28'house%20is%20open'%29%3B%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%7D%0D%0Aconst%20house%20%3D%20builder%28%29%3B%0D%0Ahouse.open%28%29%3B" rel="nofollow">following code</a>, on typescript version 1.7.5. The problem exists in typescript from the release when class expressions (<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="40826560" data-permission-text="Title is private" data-url="https://github.com/microsoft/TypeScript/issues/497" data-hovercard-type="issue" data-hovercard-url="/microsoft/TypeScript/issues/497/hovercard" href="https://github.com/microsoft/TypeScript/issues/497">#497</a>) were introduced.</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function builder() {
    return new class House {
        public open():void {
            console.info('house is open');
        }
    }
}
const house = builder();
house.open();"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">builder</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-k">new</span> <span class="pl-k">class</span> <span class="pl-smi">House</span> <span class="pl-kos">{</span>
        <span class="pl-k">public</span> <span class="pl-en">open</span><span class="pl-kos">(</span><span class="pl-kos">)</span>:<span class="pl-smi"><span class="pl-k">void</span></span> <span class="pl-kos">{</span>
            <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">info</span><span class="pl-kos">(</span><span class="pl-s">'house is open'</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">const</span> <span class="pl-s1">house</span> <span class="pl-c1">=</span> <span class="pl-en">builder</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">house</span><span class="pl-kos">.</span><span class="pl-en">open</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">is compiled to</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function builder() {
    return new (function () {
        function House() {
        }
        House.prototype.open = function () {
            console.info('house is open');
        };
        return House;
    })();
}
var house = builder();
house.open();"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">builder</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-k">new</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">House</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">House</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">.</span><span class="pl-en">open</span> <span class="pl-c1">=</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-smi">console</span><span class="pl-kos">.</span><span class="pl-en">info</span><span class="pl-kos">(</span><span class="pl-s">'house is open'</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">House</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-k">var</span> <span class="pl-s1">house</span> <span class="pl-c1">=</span> <span class="pl-en">builder</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">house</span><span class="pl-kos">.</span><span class="pl-en">open</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">and looks good, but throws in the console:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Uncaught TypeError: house.open is not a function"><pre class="notranslate"><code class="notranslate">Uncaught TypeError: house.open is not a function
</code></pre></div>
<p dir="auto">Thats, because from <code class="notranslate">builder()</code> is returned constructor of <code class="notranslate">House</code> instead of an instance. The example above works, <a href="http://www.typescriptlang.org/Playground#src=function%20builder%28%29%20%7B%0D%0A%09const%20houseConstructor%20%3D%20class%20House%20%7B%0D%0A%09%09public%20open%28%29%3Avoid%20%7B%0D%0A%09%09%09console.info%28'house%20is%20open'%29%3B%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%09return%20new%20houseConstructor%28%29%3B%0D%0A%7D%0D%0Aconst%20house%20%3D%20builder%28%29%3B%0D%0Ahouse.open%28%29%3B" rel="nofollow">when we assign constructor to a variable</a> and then, create instance with the <code class="notranslate">new</code> keyword.</p>
<p dir="auto">tested on <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/microsoft/TypeScript/commit/690b87c2097b0101969c941f085b1f660ecc1a7e/hovercard" href="https://github.com/microsoft/TypeScript/commit/690b87c2097b0101969c941f085b1f660ecc1a7e"><tt>690b87c</tt></a></p>
<p dir="auto">source code.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="new class {
    hi() {
        return &quot;Hi!&quot;;
    }
}().hi();"><pre class="notranslate"><code class="notranslate">new class {
    hi() {
        return "Hi!";
    }
}().hi();
</code></pre></div>
<p dir="auto">expected.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="new ((function () {
    function class_1() {
    }
    class_1.prototype.hi = function () {
        return &quot;Hi!&quot;;
    };
    return class_1;
})())().hi();"><pre class="notranslate"><code class="notranslate">new ((function () {
    function class_1() {
    }
    class_1.prototype.hi = function () {
        return "Hi!";
    };
    return class_1;
})())().hi();
</code></pre></div>
<p dir="auto">actual.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="new (function () {
    function class_1() {
    }
    class_1.prototype.hi = function () {
        return &quot;Hi!&quot;;
    };
    return class_1;
})()().hi();"><pre class="notranslate"><code class="notranslate">new (function () {
    function class_1() {
    }
    class_1.prototype.hi = function () {
        return "Hi!";
    };
    return class_1;
})()().hi();
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ tsc --target es5 test.ts
$ node test.js
/private/tmp/tsc-1.6/test.js:8
})()().hi();
      ^

TypeError: Cannot read property 'hi' of undefined
    at Object.&lt;anonymous&gt; (/private/tmp/tsc-1.6/test.js:8:7)
    at Module._compile (module.js:430:26)
    at Object.Module._extensions..js (module.js:448:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:471:10)
    at startup (node.js:117:18)
    at node.js:951:3"><pre class="notranslate"><code class="notranslate">$ tsc --target es5 test.ts
$ node test.js
/private/tmp/tsc-1.6/test.js:8
})()().hi();
      ^

TypeError: Cannot read property 'hi' of undefined
    at Object.&lt;anonymous&gt; (/private/tmp/tsc-1.6/test.js:8:7)
    at Module._compile (module.js:430:26)
    at Object.Module._extensions..js (module.js:448:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:471:10)
    at startup (node.js:117:18)
    at node.js:951:3
</code></pre></div>