<p dir="auto">Hi,</p>
<p dir="auto">I have an object that has an Enum as key. The Enum values get eventualy compiled to number in JS.</p>
<p dir="auto">I'd like to be able to specify this:<br>
<code class="notranslate">var mapping: { [mappingKey: MappingKey]: string; }</code><br>
(MappingKey is Enum)</p>
<p dir="auto">This doesn't work and throws compile errors.</p>
<p dir="auto">Specifying <code class="notranslate">mappingKey: number</code> is not the correct behavior, as I would be able to do this in TS code then:<br>
<code class="notranslate">mapping[5] // this should throw compile error</code></p>
<p dir="auto">This is a bit related to this issue:<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="51422283" data-permission-text="Title is private" data-url="https://github.com/microsoft/TypeScript/issues/1415" data-hovercard-type="issue" data-hovercard-url="/microsoft/TypeScript/issues/1415/hovercard" href="https://github.com/microsoft/TypeScript/issues/1415">#1415</a></p>
<blockquote>
<h2 dir="auto">ES7 proposal</h2>
<p dir="auto">The ES7 proposal for decorators can be found here: <a href="https://github.com/wycats/javascript-decorators">https://github.com/wycats/javascript-decorators</a><br>
The ES7 proposal serves as the base of this proposal. Below are notes about how the type system</p>
</blockquote>
<h2 dir="auto">Decorator targets:</h2>
<h3 dir="auto">Class constructor</h3>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@F(&quot;color&quot;)
@G
class Foo {
}"><pre class="notranslate">@<span class="pl-smi">F</span><span class="pl-kos">(</span><span class="pl-s">"color"</span><span class="pl-kos">)</span>
@<span class="pl-smi">G</span>
<span class="pl-k">class</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">desugars to:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var Foo = (function () {
    function Foo() {
    }
    Foo = __decorate([F(&quot;color&quot;), G], Foo);
    return Foo;
})();"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-v">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-v">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">Foo</span> <span class="pl-c1">=</span> <span class="pl-en">__decorate</span><span class="pl-kos">(</span><span class="pl-kos">[</span><span class="pl-v">F</span><span class="pl-kos">(</span><span class="pl-s">"color"</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-v">G</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-v">Foo</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">return</span> <span class="pl-v">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></pre></div>
<h3 dir="auto">Methods</h3>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class Foo {
  @F(color)
  @G
  bar() { }
}"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
  @<span class="pl-smi">F</span><span class="pl-kos">(</span><span class="pl-s1">color</span><span class="pl-kos">)</span>
  @<span class="pl-smi">G</span>
  <span class="pl-en">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></pre></div>
<p dir="auto">desugars to:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var Foo = (function () {
    function Foo() {
    }
    Foo.prototype.bar = function () {
    };
    Object.defineProperty(Foo.prototype, &quot;bar&quot;, __decorate([F(color), G], Foo.prototype, &quot;bar&quot;, Object.getOwnPropertyDescriptor(Foo.prototype, &quot;bar&quot;)));
    return Foo;
})();"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-v">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-v">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">Foo</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">.</span><span class="pl-en">bar</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-kos">}</span><span class="pl-kos">;</span>
    <span class="pl-v">Object</span><span class="pl-kos">.</span><span class="pl-en">defineProperty</span><span class="pl-kos">(</span><span class="pl-v">Foo</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">,</span> <span class="pl-s">"bar"</span><span class="pl-kos">,</span> <span class="pl-en">__decorate</span><span class="pl-kos">(</span><span class="pl-kos">[</span><span class="pl-v">F</span><span class="pl-kos">(</span><span class="pl-s1">color</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-v">G</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-v">Foo</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">,</span> <span class="pl-s">"bar"</span><span class="pl-kos">,</span> <span class="pl-v">Object</span><span class="pl-kos">.</span><span class="pl-en">getOwnPropertyDescriptor</span><span class="pl-kos">(</span><span class="pl-v">Foo</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">,</span> <span class="pl-s">"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-v">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></pre></div>
<h2 dir="auto">Static method</h2>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class Foo {
    @F(&quot;color&quot;)
    @G
    static sMethod() {}
}"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
    @<span class="pl-smi">F</span><span class="pl-kos">(</span><span class="pl-s">"color"</span><span class="pl-kos">)</span>
    @<span class="pl-smi">G</span>
    <span class="pl-k">static</span> <span class="pl-en">sMethod</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">desugars to:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var Foo = (function () {
    function Foo() {
    }
    Foo.sMethod = function () {
    };
    Object.defineProperty(Foo, &quot;sMethod&quot;, __decorate([F(&quot;color&quot;), G], Foo, &quot;sMethod&quot;, Object.getOwnPropertyDescriptor(Foo, &quot;sMethod&quot;)));
    return Foo;
})();"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-v">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-v">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">Foo</span><span class="pl-kos">.</span><span class="pl-en">sMethod</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-kos">}</span><span class="pl-kos">;</span>
    <span class="pl-v">Object</span><span class="pl-kos">.</span><span class="pl-en">defineProperty</span><span class="pl-kos">(</span><span class="pl-v">Foo</span><span class="pl-kos">,</span> <span class="pl-s">"sMethod"</span><span class="pl-kos">,</span> <span class="pl-en">__decorate</span><span class="pl-kos">(</span><span class="pl-kos">[</span><span class="pl-v">F</span><span class="pl-kos">(</span><span class="pl-s">"color"</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-v">G</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-v">Foo</span><span class="pl-kos">,</span> <span class="pl-s">"sMethod"</span><span class="pl-kos">,</span> <span class="pl-v">Object</span><span class="pl-kos">.</span><span class="pl-en">getOwnPropertyDescriptor</span><span class="pl-kos">(</span><span class="pl-v">Foo</span><span class="pl-kos">,</span> <span class="pl-s">"sMethod"</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">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></pre></div>
<h3 dir="auto">Properties</h3>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class Foo {
    @F(&quot;color&quot;)
    @G
    prop: number;
}"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
    @<span class="pl-smi">F</span><span class="pl-kos">(</span><span class="pl-s">"color"</span><span class="pl-kos">)</span>
    @<span class="pl-smi">G</span>
    <span class="pl-c1">prop</span>: <span class="pl-smi">number</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">desugars to:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var Foo = (function () {
    function Foo() {
    }
    __decorate([F(&quot;color&quot;), G], Foo.prototype, &quot;prop&quot;);
    return Foo;
})();"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-v">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-v">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-en">__decorate</span><span class="pl-kos">(</span><span class="pl-kos">[</span><span class="pl-v">F</span><span class="pl-kos">(</span><span class="pl-s">"color"</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-v">G</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-v">Foo</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">,</span> <span class="pl-s">"prop"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">return</span> <span class="pl-v">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></pre></div>
<h3 dir="auto">Method/Accessor formal parameter</h3>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class Foo {
    method(@G a, @F(&quot;color&quot;) b) {}
}"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
    <span class="pl-en">method</span><span class="pl-kos">(</span>@<span class="pl-smi">G</span> <span class="pl-s1">a</span><span class="pl-kos">,</span> @<span class="pl-smi">F</span><span class="pl-kos">(</span><span class="pl-s">"color"</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-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">desugars to:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var Foo = (function () {
    function Foo() {
    }
    Foo.prototype.method = function (a, b) {
    };
    __decorate([G], Foo.prototype, &quot;method&quot;, 0);
    __decorate([F(&quot;color&quot;)], Foo.prototype, &quot;method&quot;, 1);
    return Foo;
})();"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-v">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-v">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">Foo</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">.</span><span class="pl-en">method</span> <span class="pl-c1">=</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-s1">b</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">__decorate</span><span class="pl-kos">(</span><span class="pl-kos">[</span><span class="pl-v">G</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-v">Foo</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">,</span> <span class="pl-s">"method"</span><span class="pl-kos">,</span> <span class="pl-c1">0</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-en">__decorate</span><span class="pl-kos">(</span><span class="pl-kos">[</span><span class="pl-v">F</span><span class="pl-kos">(</span><span class="pl-s">"color"</span><span class="pl-kos">)</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-v">Foo</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">,</span> <span class="pl-s">"method"</span><span class="pl-kos">,</span> <span class="pl-c1">1</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">return</span> <span class="pl-v">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></pre></div>
<p dir="auto">Where the __decorate is defined as:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var __decorate = this.__decorate || function (decorators, target, key, value) {
    var kind = typeof (arguments.length == 2 ? value = target : value);
    for (var i = decorators.length - 1; i &gt;= 0; --i) {
        var decorator = decorators[i];
        switch (kind) {
            case &quot;function&quot;: value = decorator(value) || value; break;
            case &quot;number&quot;: decorator(target, key, value); break;
            case &quot;undefined&quot;: decorator(target, key); break;
            case &quot;object&quot;: value = decorator(target, key, value) || value; break;
        }
    }
    return value;
};"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">__decorate</span> <span class="pl-c1">=</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">__decorate</span> <span class="pl-c1">||</span> <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">decorators</span><span class="pl-kos">,</span> <span class="pl-s1">target</span><span class="pl-kos">,</span> <span class="pl-s1">key</span><span class="pl-kos">,</span> <span class="pl-s1">value</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">var</span> <span class="pl-s1">kind</span> <span class="pl-c1">=</span> <span class="pl-k">typeof</span> <span class="pl-kos">(</span><span class="pl-smi">arguments</span><span class="pl-kos">.</span><span class="pl-c1">length</span> <span class="pl-c1">==</span> <span class="pl-c1">2</span> ? <span class="pl-s1">value</span> <span class="pl-c1">=</span> <span class="pl-s1">target</span> : <span class="pl-s1">value</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">i</span> <span class="pl-c1">=</span> <span class="pl-s1">decorators</span><span class="pl-kos">.</span><span class="pl-c1">length</span> <span class="pl-c1">-</span> <span class="pl-c1">1</span><span class="pl-kos">;</span> <span class="pl-s1">i</span> <span class="pl-c1">&gt;=</span> <span class="pl-c1">0</span><span class="pl-kos">;</span> <span class="pl-c1">--</span><span class="pl-s1">i</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">var</span> <span class="pl-s1">decorator</span> <span class="pl-c1">=</span> <span class="pl-s1">decorators</span><span class="pl-kos">[</span><span class="pl-s1">i</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
        <span class="pl-k">switch</span> <span class="pl-kos">(</span><span class="pl-s1">kind</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-k">case</span> <span class="pl-s">"function"</span>: <span class="pl-s1">value</span> <span class="pl-c1">=</span> <span class="pl-s1">decorator</span><span class="pl-kos">(</span><span class="pl-s1">value</span><span class="pl-kos">)</span> <span class="pl-c1">||</span> <span class="pl-s1">value</span><span class="pl-kos">;</span> <span class="pl-k">break</span><span class="pl-kos">;</span>
            <span class="pl-k">case</span> <span class="pl-s">"number"</span>: <span class="pl-s1">decorator</span><span class="pl-kos">(</span><span class="pl-s1">target</span><span class="pl-kos">,</span> <span class="pl-s1">key</span><span class="pl-kos">,</span> <span class="pl-s1">value</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-k">break</span><span class="pl-kos">;</span>
            <span class="pl-k">case</span> <span class="pl-s">"undefined"</span>: <span class="pl-s1">decorator</span><span class="pl-kos">(</span><span class="pl-s1">target</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-k">break</span><span class="pl-kos">;</span>
            <span class="pl-k">case</span> <span class="pl-s">"object"</span>: <span class="pl-s1">value</span> <span class="pl-c1">=</span> <span class="pl-s1">decorator</span><span class="pl-kos">(</span><span class="pl-s1">target</span><span class="pl-kos">,</span> <span class="pl-s1">key</span><span class="pl-kos">,</span> <span class="pl-s1">value</span><span class="pl-kos">)</span> <span class="pl-c1">||</span> <span class="pl-s1">value</span><span class="pl-kos">;</span> <span class="pl-k">break</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">value</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span></pre></div>
<h2 dir="auto">Decorator signatures:</h2>
<p dir="auto">A valid decorator should be:</p>
<ol dir="auto">
<li>Assignable to one of the Decorator types (ClassDecorator | PropertyDecorator | MethodDecorator | ParameterDecorator) as described below.</li>
<li>Return a value (in the case of class decorators and method decorator) that is assignable to the decorated value.</li>
</ol>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="declare type ClassDecorator = &lt;TFunction extends Function&gt;(target: TFunction) =&gt; TFunction | void;
declare type PropertyDecorator = (target: Object, propertyKey: string | symbol) =&gt; void;
declare type MethodDecorator = &lt;T&gt;(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor&lt;T&gt;) =&gt; TypedPropertyDescriptor&lt;T&gt; | void;
declare type ParameterDecorator = (target: Function, propertyKey: string | symbol, parameterIndex: number) =&gt; void;"><pre class="notranslate"><span class="pl-k">declare</span> <span class="pl-k">type</span> <span class="pl-smi">ClassDecorator</span> <span class="pl-c1">=</span> <span class="pl-c1">&lt;</span><span class="pl-smi">TFunction</span> <span class="pl-k">extends</span> <span class="pl-smi">Function</span><span class="pl-c1">&gt;</span><span class="pl-kos">(</span><span class="pl-s1">target</span>: <span class="pl-smi">TFunction</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-smi">TFunction</span> <span class="pl-c1">|</span> <span class="pl-smi"><span class="pl-k">void</span></span><span class="pl-kos">;</span>
<span class="pl-k">declare</span> <span class="pl-k">type</span> <span class="pl-smi">PropertyDecorator</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span><span class="pl-s1">target</span>: <span class="pl-smi">Object</span><span class="pl-kos">,</span> <span class="pl-s1">propertyKey</span>: <span class="pl-smi">string</span> <span class="pl-c1">|</span> <span class="pl-smi">symbol</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-smi"><span class="pl-k">void</span></span><span class="pl-kos">;</span>
<span class="pl-k">declare</span> <span class="pl-k">type</span> <span class="pl-smi">MethodDecorator</span> <span class="pl-c1">=</span> <span class="pl-c1">&lt;</span><span class="pl-smi">T</span><span class="pl-c1">&gt;</span><span class="pl-kos">(</span><span class="pl-s1">target</span>: <span class="pl-smi">Object</span><span class="pl-kos">,</span> <span class="pl-s1">propertyKey</span>: <span class="pl-smi">string</span> <span class="pl-c1">|</span> <span class="pl-smi">symbol</span><span class="pl-kos">,</span> <span class="pl-s1">descriptor</span>: <span class="pl-smi">TypedPropertyDescriptor</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-smi">TypedPropertyDescriptor</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span> <span class="pl-c1">|</span> <span class="pl-smi"><span class="pl-k">void</span></span><span class="pl-kos">;</span>
<span class="pl-k">declare</span> <span class="pl-k">type</span> <span class="pl-smi">ParameterDecorator</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span><span class="pl-s1">target</span>: <span class="pl-smi">Function</span><span class="pl-kos">,</span> <span class="pl-s1">propertyKey</span>: <span class="pl-smi">string</span> <span class="pl-c1">|</span> <span class="pl-smi">symbol</span><span class="pl-kos">,</span> <span class="pl-s1">parameterIndex</span>: <span class="pl-smi">number</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-smi"><span class="pl-k">void</span></span><span class="pl-kos">;</span></pre></div>
<h3 dir="auto">Notes:</h3>
<ul dir="auto">
<li>Decorating a function declaration is not allowed as it will block hoisting the function to the top of the scope, which is a significant change in semantics.</li>
<li>Decorating function expressions and arrow functions are not supported. The same effect can be achived by applying the decorator function as <code class="notranslate">var x = dec(function () { });</code></li>
<li>Decorating function formal parameters is currently not part of the ES7 proposal.</li>
<li>Decorators are not allowed when targeting ES3</li>
</ul>