<p dir="auto">It seems that one of the likeable features of TypeScript, compared to Babel lets say, is that it emits readable code.</p>
<p dir="auto">Consider the following code:</p>
<p dir="auto">X.ts:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="namespace a.b.x {
    class X {

    }
}"><pre class="notranslate"><span class="pl-k">namespace</span> <span class="pl-s1">a</span><span class="pl-kos">.</span><span class="pl-s1">b</span><span class="pl-kos">.</span><span class="pl-s1">x</span> <span class="pl-kos">{</span>
    <span class="pl-k">class</span> <span class="pl-smi">X</span> <span class="pl-kos">{</span>

    <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Y.ts:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="namespace a.b.y {
    class y {

    }
}"><pre class="notranslate"><span class="pl-k">namespace</span> <span class="pl-s1">a</span><span class="pl-kos">.</span><span class="pl-s1">b</span><span class="pl-kos">.</span><span class="pl-s1">y</span> <span class="pl-kos">{</span>
    <span class="pl-k">class</span> <span class="pl-smi">y</span> <span class="pl-kos">{</span>

    <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">This emits:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var a;
(function (a) {
    var b;
    (function (b) {
        var x;
        (function (x) {
            var X = (function () {
                function X() {
                }
                return X;
            })();
        })(x = b.x || (b.x = {}));
    })(b = a.b || (a.b = {}));
})(a || (a = {}));

var a;
(function (a) {
    var b;
    (function (b) {
        var y;
        (function (y_1) {
            var y = (function () {
                function y() {
                }
                return y;
            })();
        })(y = b.y || (b.y = {}));
    })(b = a.b || (a.b = {}));
})(a || (a = {}));"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">a</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">a</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">var</span> <span class="pl-s1">b</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">b</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">var</span> <span class="pl-s1">x</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">x</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-k">var</span> <span class="pl-v">X</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">X</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">X</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-kos">)</span><span class="pl-kos">(</span><span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">b</span><span class="pl-kos">.</span><span class="pl-c1">x</span> <span class="pl-c1">||</span> <span class="pl-kos">(</span><span class="pl-s1">b</span><span class="pl-kos">.</span><span class="pl-c1">x</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-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-s1">a</span><span class="pl-kos">.</span><span class="pl-c1">b</span> <span class="pl-c1">||</span> <span class="pl-kos">(</span><span class="pl-s1">a</span><span class="pl-kos">.</span><span class="pl-c1">b</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-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-s1">a</span> <span class="pl-c1">||</span> <span class="pl-kos">(</span><span class="pl-s1">a</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">a</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">a</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">var</span> <span class="pl-s1">b</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">b</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">var</span> <span class="pl-s1">y</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">y_1</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-k">var</span> <span class="pl-s1">y</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-s1">y</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-s1">y</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-kos">)</span><span class="pl-kos">(</span><span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">b</span><span class="pl-kos">.</span><span class="pl-c1">y</span> <span class="pl-c1">||</span> <span class="pl-kos">(</span><span class="pl-s1">b</span><span class="pl-kos">.</span><span class="pl-c1">y</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-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-s1">a</span><span class="pl-kos">.</span><span class="pl-c1">b</span> <span class="pl-c1">||</span> <span class="pl-kos">(</span><span class="pl-s1">a</span><span class="pl-kos">.</span><span class="pl-c1">b</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-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-s1">a</span> <span class="pl-c1">||</span> <span class="pl-kos">(</span><span class="pl-s1">a</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">There's a lot of code redundancy, which can really clutter the emitted output for projects that rely heavily on namespaces.</p>
<p dir="auto">Wouldn't it be nice if we could just do something like this:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="namespace a.b {
    export namespace x {
        /// include X.ts
    }
    export namespace y {
        /// include Y.ts
    }
}"><pre class="notranslate"><span class="pl-k">namespace</span> <span class="pl-s1">a</span><span class="pl-kos">.</span><span class="pl-s1">b</span> <span class="pl-kos">{</span>
    <span class="pl-k">export</span> <span class="pl-k">namespace</span> <span class="pl-s1">x</span> <span class="pl-kos">{</span>
        <span class="pl-c">/// include X.ts</span>
    <span class="pl-kos">}</span>
    <span class="pl-k">export</span> <span class="pl-k">namespace</span> <span class="pl-s1">y</span> <span class="pl-kos">{</span>
        <span class="pl-c">/// include Y.ts</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">The include statement simply places the included file into the script during pre-compilation.</p>
<p dir="auto">My guess is that this is already partly implemented with <code class="notranslate">/// reference</code>, only that <code class="notranslate">///reference</code> doesn't seem to work unless it's either the first line, or one succeeding another <code class="notranslate">/// reference</code>.</p>
<p dir="auto">We have a typescript application and a use a file per class. There are lots of benefits to this the major one being source control conflict reduction.</p>
<p dir="auto">We compile our app using the --out compiler flag but I think there is room for some serious optimization of the compilers output for modules.</p>
<p dir="auto">Currently if you have two classes defined in separate files the compile generates the following JavaScript.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var Example;
(function (Example) {
    (function (Nested) {
        (function (Issue) {
            var bar = (function () {
                function bar() {
                }
                return bar;
            })();
            Issue.bar = bar;
        })(Nested.Issue || (Nested.Issue = {}));
        var Issue = Nested.Issue;
    })(Example.Nested || (Example.Nested = {}));
    var Nested = Example.Nested;
})(Example || (Example = {}));

var Example;
(function (Example) {
    (function (Nested) {
        (function (Issue) {
            var foo = (function () {
                function foo() {
                }
                return foo;
            })();
            Issue.foo = foo;
        })(Nested.Issue || (Nested.Issue = {}));
        var Issue = Nested.Issue;
    })(Example.Nested || (Example.Nested = {}));
    var Nested = Example.Nested;
})(Example || (Example = {}));"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-v">Example</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-v">Example</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-kos">(</span><span class="pl-v">Nested</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-kos">(</span><span class="pl-v">Issue</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-k">var</span> <span class="pl-s1">bar</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-s1">bar</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-s1">bar</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-v">Issue</span><span class="pl-kos">.</span><span class="pl-c1">bar</span> <span class="pl-c1">=</span> <span class="pl-s1">bar</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">Nested</span><span class="pl-kos">.</span><span class="pl-c1">Issue</span> <span class="pl-c1">||</span> <span class="pl-kos">(</span><span class="pl-v">Nested</span><span class="pl-kos">.</span><span class="pl-c1">Issue</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-v">Issue</span> <span class="pl-c1">=</span> <span class="pl-v">Nested</span><span class="pl-kos">.</span><span class="pl-c1">Issue</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">Example</span><span class="pl-kos">.</span><span class="pl-c1">Nested</span> <span class="pl-c1">||</span> <span class="pl-kos">(</span><span class="pl-v">Example</span><span class="pl-kos">.</span><span class="pl-c1">Nested</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-v">Nested</span> <span class="pl-c1">=</span> <span class="pl-v">Example</span><span class="pl-kos">.</span><span class="pl-c1">Nested</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">Example</span> <span class="pl-c1">||</span> <span class="pl-kos">(</span><span class="pl-v">Example</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-v">Example</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-v">Example</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-kos">(</span><span class="pl-v">Nested</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-kos">(</span><span class="pl-v">Issue</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-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-s1">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-k">return</span> <span class="pl-s1">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-kos">)</span><span class="pl-kos">;</span>
            <span class="pl-v">Issue</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-kos">)</span><span class="pl-kos">(</span><span class="pl-v">Nested</span><span class="pl-kos">.</span><span class="pl-c1">Issue</span> <span class="pl-c1">||</span> <span class="pl-kos">(</span><span class="pl-v">Nested</span><span class="pl-kos">.</span><span class="pl-c1">Issue</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-v">Issue</span> <span class="pl-c1">=</span> <span class="pl-v">Nested</span><span class="pl-kos">.</span><span class="pl-c1">Issue</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">Example</span><span class="pl-kos">.</span><span class="pl-c1">Nested</span> <span class="pl-c1">||</span> <span class="pl-kos">(</span><span class="pl-v">Example</span><span class="pl-kos">.</span><span class="pl-c1">Nested</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-v">Nested</span> <span class="pl-c1">=</span> <span class="pl-v">Example</span><span class="pl-kos">.</span><span class="pl-c1">Nested</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">Example</span> <span class="pl-c1">||</span> <span class="pl-kos">(</span><span class="pl-v">Example</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">I suggest a compiler flag that composes all classes/ functions etc under a single module declaration? So the output code would be like the example below. This would dramatically reduce the size of the JavaScript the compiler outputs. I estimate that our app which currently compiles to around 15,000 lines of probably be only be 2000 lines if this were available.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var Example;
(function (Example) {
    (function (Nested) {
        (function (Issue) {
            var bar = (function () {
                function bar() {
                }
                return bar;
            })();
            Issue.bar = bar;
            var foo = (function () {
                function foo() {
                }
                return foo;
            })();
            Issue.foo = foo;
        })(Nested.Issue || (Nested.Issue = {}));
        var Issue = Nested.Issue;
    })(Example.Nested || (Example.Nested = {}));
    var Nested = Example.Nested;
})(Example || (Example = {}));"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-v">Example</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-v">Example</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-kos">(</span><span class="pl-v">Nested</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-kos">(</span><span class="pl-v">Issue</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-k">var</span> <span class="pl-s1">bar</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-s1">bar</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-s1">bar</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-v">Issue</span><span class="pl-kos">.</span><span class="pl-c1">bar</span> <span class="pl-c1">=</span> <span class="pl-s1">bar</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-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-s1">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-k">return</span> <span class="pl-s1">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-kos">)</span><span class="pl-kos">;</span>
            <span class="pl-v">Issue</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-kos">)</span><span class="pl-kos">(</span><span class="pl-v">Nested</span><span class="pl-kos">.</span><span class="pl-c1">Issue</span> <span class="pl-c1">||</span> <span class="pl-kos">(</span><span class="pl-v">Nested</span><span class="pl-kos">.</span><span class="pl-c1">Issue</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-v">Issue</span> <span class="pl-c1">=</span> <span class="pl-v">Nested</span><span class="pl-kos">.</span><span class="pl-c1">Issue</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">Example</span><span class="pl-kos">.</span><span class="pl-c1">Nested</span> <span class="pl-c1">||</span> <span class="pl-kos">(</span><span class="pl-v">Example</span><span class="pl-kos">.</span><span class="pl-c1">Nested</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-v">Nested</span> <span class="pl-c1">=</span> <span class="pl-v">Example</span><span class="pl-kos">.</span><span class="pl-c1">Nested</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">Example</span> <span class="pl-c1">||</span> <span class="pl-kos">(</span><span class="pl-v">Example</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>