<p dir="auto">TS 1.7.5, Target ES6, Environment Windows 8.1, Node 5.6</p>
<p dir="auto">Since switching the "target" to ES 6, "target.name" is empty in class decorators. With ES5 ist worked as expected.</p>
<p dir="auto">I'm decorating my classes with class and property decorators:</p>
<p dir="auto">The decorated TS class:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@sg.DMClass
export class User implements IUser {
    @sg.DMProperty
    firstName: string;
    @sg.DMProperty
    lastName: string;
    @sg.DMProperty
    friends: User[];
    @sg.DMProperty
    blogPosts: BlogPost[];
    @sg.DMProperty
    test: User;
}"><pre class="notranslate">@<span class="pl-s1">sg</span><span class="pl-kos">.</span><span class="pl-c1">DMClass</span>
<span class="pl-k">export</span> <span class="pl-k">class</span> <span class="pl-v">User</span> <span class="pl-s1">implements</span> <span class="pl-v">IUser</span> <span class="pl-kos">{</span>
    @<span class="pl-s1">sg</span><span class="pl-kos">.</span><span class="pl-c1">DMProperty</span>
    <span class="pl-c1">firstName</span>: <span class="pl-s1">string</span><span class="pl-kos">;</span>
    @<span class="pl-s1">sg</span><span class="pl-kos">.</span><span class="pl-c1">DMProperty</span>
    <span class="pl-c1">lastName</span>: <span class="pl-s1">string</span><span class="pl-kos">;</span>
    @<span class="pl-s1">sg</span><span class="pl-kos">.</span><span class="pl-c1">DMProperty</span>
    <span class="pl-c1">friends</span>: <span class="pl-v">User</span><span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
    @<span class="pl-s1">sg</span><span class="pl-kos">.</span><span class="pl-c1">DMProperty</span>
    <span class="pl-c1">blogPosts</span>: <span class="pl-v">BlogPost</span><span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
    @<span class="pl-s1">sg</span><span class="pl-kos">.</span><span class="pl-c1">DMProperty</span>
    <span class="pl-c1">test</span>: <span class="pl-c1">User</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">The TS decorator:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="export function DMClass(target: any) {
    var t = Reflect.getMetadata(&quot;design:paramtypes&quot;, target);
    var om = Reflect.getOwnMetadataKeys(target);
    console.log(&quot;schemaGen.DMClass: target: %s: %O&quot;, target.name, target);
    var schema = target.prototype[Schema];
    target[IsDomainClass] = true;
    target[Schema] = target.prototype[Schema];
    schema.class = target.name;
    console.log(&quot;schemaGen.DMClass: schema: %O&quot;, schema);
}"><pre class="notranslate"><span class="pl-k">export</span> <span class="pl-k">function</span> <span class="pl-v">DMClass</span><span class="pl-kos">(</span><span class="pl-s1">target</span>: <span class="pl-s1">any</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">var</span> <span class="pl-s1">t</span> <span class="pl-c1">=</span> <span class="pl-v">Reflect</span><span class="pl-kos">.</span><span class="pl-en">getMetadata</span><span class="pl-kos">(</span><span class="pl-s">"design:paramtypes"</span><span class="pl-kos">,</span> <span class="pl-s1">target</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">var</span> <span class="pl-s1">om</span> <span class="pl-c1">=</span> <span class="pl-v">Reflect</span><span class="pl-kos">.</span><span class="pl-en">getOwnMetadataKeys</span><span class="pl-kos">(</span><span class="pl-s1">target</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">log</span><span class="pl-kos">(</span><span class="pl-s">"schemaGen.DMClass: target: %s: %O"</span><span class="pl-kos">,</span> <span class="pl-s1">target</span><span class="pl-kos">.</span><span class="pl-c1">name</span><span class="pl-kos">,</span> <span class="pl-s1">target</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">var</span> <span class="pl-s1">schema</span> <span class="pl-c1">=</span> <span class="pl-s1">target</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">[</span><span class="pl-v">Schema</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
    <span class="pl-s1">target</span><span class="pl-kos">[</span><span class="pl-v">IsDomainClass</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-c1">true</span><span class="pl-kos">;</span>
    <span class="pl-s1">target</span><span class="pl-kos">[</span><span class="pl-v">Schema</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-s1">target</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">[</span><span class="pl-v">Schema</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
    <span class="pl-s1">schema</span><span class="pl-kos">.</span><span class="pl-c1">class</span> <span class="pl-c1">=</span> <span class="pl-s1">target</span><span class="pl-kos">.</span><span class="pl-c1">name</span><span class="pl-kos">;</span>
    <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"schemaGen.DMClass: schema: %O"</span><span class="pl-kos">,</span> <span class="pl-s1">schema</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><strong>Current (faulty) behaviour:</strong><br>
So "target.name" is empty. Having a look at the generated js file seems to reveal the problem:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var gq = require(&quot;./gq&quot;);
var sg = require(&quot;./schemaGen&quot;);
var cons = console;
let User = class {
};
__decorate([
    sg.DMProperty, 
    __metadata('design:type', String)
], User.prototype, &quot;firstName&quot;, void 0);
__decorate([
    sg.DMProperty, 
    __metadata('design:type', String)
], User.prototype, &quot;lastName&quot;, void 0);
__decorate([
    sg.DMProperty, 
    __metadata('design:type', {name: 'Array&lt;User&gt;', type:'Array', elemType:'User'})
], User.prototype, &quot;friends&quot;, void 0);
__decorate([
    sg.DMProperty, 
    __metadata('design:type', {name: 'Array&lt;BlogPost&gt;', type:'Array', elemType:'BlogPost'})
], User.prototype, &quot;blogPosts&quot;, void 0);
__decorate([
    sg.DMProperty, 
    __metadata('design:type', User)
], User.prototype, &quot;test&quot;, void 0);
User = __decorate([
    sg.DMClass, 
    __metadata('design:paramtypes', [])
], User);
exports.User = User;"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">gq</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">"./gq"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-s1">sg</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">"./schemaGen"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-s1">cons</span> <span class="pl-c1">=</span> <span class="pl-smi">console</span><span class="pl-kos">;</span>
<span class="pl-k">let</span> <span class="pl-v">User</span> <span class="pl-c1">=</span> <span class="pl-k">class</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-s1">sg</span><span class="pl-kos">.</span><span class="pl-c1">DMProperty</span><span class="pl-kos">,</span> 
    <span class="pl-en">__metadata</span><span class="pl-kos">(</span><span class="pl-s">'design:type'</span><span class="pl-kos">,</span> <span class="pl-v">String</span><span class="pl-kos">)</span>
<span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-v">User</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">,</span> <span class="pl-s">"firstName"</span><span class="pl-kos">,</span> <span class="pl-k">void</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-s1">sg</span><span class="pl-kos">.</span><span class="pl-c1">DMProperty</span><span class="pl-kos">,</span> 
    <span class="pl-en">__metadata</span><span class="pl-kos">(</span><span class="pl-s">'design:type'</span><span class="pl-kos">,</span> <span class="pl-v">String</span><span class="pl-kos">)</span>
<span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-v">User</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">,</span> <span class="pl-s">"lastName"</span><span class="pl-kos">,</span> <span class="pl-k">void</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-s1">sg</span><span class="pl-kos">.</span><span class="pl-c1">DMProperty</span><span class="pl-kos">,</span> 
    <span class="pl-en">__metadata</span><span class="pl-kos">(</span><span class="pl-s">'design:type'</span><span class="pl-kos">,</span> <span class="pl-kos">{</span><span class="pl-c1">name</span>: <span class="pl-s">'Array&lt;User&gt;'</span><span class="pl-kos">,</span> <span class="pl-c1">type</span>:<span class="pl-s">'Array'</span><span class="pl-kos">,</span> <span class="pl-c1">elemType</span>:<span class="pl-s">'User'</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">User</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">,</span> <span class="pl-s">"friends"</span><span class="pl-kos">,</span> <span class="pl-k">void</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-s1">sg</span><span class="pl-kos">.</span><span class="pl-c1">DMProperty</span><span class="pl-kos">,</span> 
    <span class="pl-en">__metadata</span><span class="pl-kos">(</span><span class="pl-s">'design:type'</span><span class="pl-kos">,</span> <span class="pl-kos">{</span><span class="pl-c1">name</span>: <span class="pl-s">'Array&lt;BlogPost&gt;'</span><span class="pl-kos">,</span> <span class="pl-c1">type</span>:<span class="pl-s">'Array'</span><span class="pl-kos">,</span> <span class="pl-c1">elemType</span>:<span class="pl-s">'BlogPost'</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">User</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">,</span> <span class="pl-s">"blogPosts"</span><span class="pl-kos">,</span> <span class="pl-k">void</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-s1">sg</span><span class="pl-kos">.</span><span class="pl-c1">DMProperty</span><span class="pl-kos">,</span> 
    <span class="pl-en">__metadata</span><span class="pl-kos">(</span><span class="pl-s">'design:type'</span><span class="pl-kos">,</span> <span class="pl-v">User</span><span class="pl-kos">)</span>
<span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-v">User</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">,</span> <span class="pl-s">"test"</span><span class="pl-kos">,</span> <span class="pl-k">void</span> <span class="pl-c1">0</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-v">User</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-s1">sg</span><span class="pl-kos">.</span><span class="pl-c1">DMClass</span><span class="pl-kos">,</span> 
    <span class="pl-en">__metadata</span><span class="pl-kos">(</span><span class="pl-s">'design:paramtypes'</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">User</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">exports</span><span class="pl-kos">.</span><span class="pl-c1">User</span> <span class="pl-c1">=</span> <span class="pl-v">User</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Expected behaviour:</strong><br>
So TS generates class without name. I think it should generate following:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="let User = class User {
};"><pre class="notranslate"><span class="pl-k">let</span> <span class="pl-v">User</span> <span class="pl-c1">=</span> <span class="pl-k">class</span> <span class="pl-v">User</span> <span class="pl-kos">{</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Manually adding "User" as class name of course solves the problem, because then "target.name"( == "class.name") is just accessing an ES 6 property.</p>
<p dir="auto">Any help ist appreciated,<br>
best Mind</p>
<p dir="auto">I have decorator:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="export function Document() {
   return function(objectConstructor: Function) {
        console.log(objectConstructor.name); // when targeting es5 it gives me what I want - the name of my class. When targeting es6 it does not give anything
    }
}"><pre class="notranslate"><span class="pl-k">export</span> <span class="pl-k">function</span> <span class="pl-smi">Document</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">function</span><span class="pl-kos">(</span><span class="pl-s1">objectConstructor</span>: <span class="pl-smi">Function</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">log</span><span class="pl-kos">(</span><span class="pl-s1">objectConstructor</span><span class="pl-kos">.</span><span class="pl-c1">name</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// when targeting es5 it gives me what I want - the name of my class. When targeting es6 it does not give anything</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Here is decorator usage:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@Document()
export class User {
}"><pre class="notranslate">@<span class="pl-smi">Document</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
<span class="pl-k">export</span> <span class="pl-k">class</span> <span class="pl-smi">User</span> <span class="pl-kos">{</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Im using "User" class name to create a document called "User", I need information how class is called. I always used es5, but now when I switched to es6 compile target I dont have information about class name anymore. Is it a bug, or it by design? If second then what is the way to get the class name?</p>