<p dir="auto">ECMAScript has the concept of implementation defined <a href="http://es5.github.io/#x15.1" rel="nofollow">global object</a>, so that properties of the <em>window</em> object in a web page can be accessed globally. Implementing this can eliminate a bunch of duplicated declarations in the default lib and also make it easier to target other runtime environments.</p>
<blockquote>
<p dir="auto">Suggestion moved over from <a href="https://typescript.codeplex.com/workitem/2609" rel="nofollow">codeplex</a></p>
</blockquote>
<p dir="auto">I was working with a rather large enum type with more than 50 items in it. Some of the item names are rather long. Given that TypeScript repeats each item string twice in the JavaScript implementation, the output starts to look rather ugly at some point.</p>
<p dir="auto">I mean:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="enum MyEnum {
    SOME_BIG_UGLY_NAME_THAT_I_CANNOT_ABBREVIATE
}"><pre class="notranslate"><span class="pl-k">enum</span> <span class="pl-smi">MyEnum</span> <span class="pl-kos">{</span>
    <span class="pl-c1">SOME_BIG_UGLY_NAME_THAT_I_CANNOT_ABBREVIATE</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">compiles to:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var MyEnum;
(function (MyEnum) {
    MyEnum[MyEnum[&quot;SOME_BIG_UGLY_NAME_THAT_I_CANNOT_ABBREVIATE&quot;] = 0] = &quot;SOME_BIG_UGLY_NAME_THAT_I_CANNOT_ABBREVIATE&quot;;
})(MyEnum || (MyEnum = {}));"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-smi">MyEnum</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-smi">MyEnum</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-smi">MyEnum</span><span class="pl-kos">[</span><span class="pl-smi">MyEnum</span><span class="pl-kos">[</span><span class="pl-s">"SOME_BIG_UGLY_NAME_THAT_I_CANNOT_ABBREVIATE"</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">"SOME_BIG_UGLY_NAME_THAT_I_CANNOT_ABBREVIATE"</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-smi">MyEnum</span> <span class="pl-c1">||</span> <span class="pl-kos">(</span><span class="pl-smi">MyEnum</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 was thinking why not repeat the number part instead (to avoid bringing duplicate string literal):</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var MyEnum;
(function (MyEnum) {
    MyEnum[MyEnum[0] = &quot;SOME_BIG_UGLY_NAME_THAT_I_CANNOT_ABBREVIATE&quot;] = 0;
})(MyEnum || (MyEnum = {}));"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-smi">MyEnum</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-smi">MyEnum</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-smi">MyEnum</span><span class="pl-kos">[</span><span class="pl-smi">MyEnum</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-s">"SOME_BIG_UGLY_NAME_THAT_I_CANNOT_ABBREVIATE"</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-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-smi">MyEnum</span> <span class="pl-c1">||</span> <span class="pl-kos">(</span><span class="pl-smi">MyEnum</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, for enums with many items not use an iterator? like:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var MyEnum;
(function (MyEnum) {
    MyEnum[&quot;SOME_BIG_UGLY_NAME_THAT_I_CANNOT_ABBREVIATE&quot;] = 0;
    //...
    //...
    //...
})(MyEnum || (MyEnum = {}));
for (var key in MyEnum) {
    MyEnum[MyEnum[key]] = key;
}"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-smi">MyEnum</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-smi">MyEnum</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-smi">MyEnum</span><span class="pl-kos">[</span><span class="pl-s">"SOME_BIG_UGLY_NAME_THAT_I_CANNOT_ABBREVIATE"</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-c">//...</span>
    <span class="pl-c">//...</span>
    <span class="pl-c">//...</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-smi">MyEnum</span> <span class="pl-c1">||</span> <span class="pl-kos">(</span><span class="pl-smi">MyEnum</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">for</span> <span class="pl-kos">(</span><span class="pl-k">var</span> <span class="pl-s1">key</span> <span class="pl-k">in</span> <span class="pl-smi">MyEnum</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-smi">MyEnum</span><span class="pl-kos">[</span><span class="pl-smi">MyEnum</span><span class="pl-kos">[</span><span class="pl-s1">key</span><span class="pl-kos">]</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-s1">key</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Thanks!</p>