title: TypeScript custom decorator on model
body: <p>I have a class as follows:</p>
  
  <pre><code>class Person {
     @indexField
     id : number;
     name : string;
  }
  </code></pre>
  
  <p>Now I want to implement a method (nevermind design, just an example) - that will allow me to dynamically get the index field.</p>
  
  <p>So,</p>
  
  <pre><code>    class Person {
         @indexField
         id : number;
         name : string;
  
         public function getIndex(){
            //Find which property is marked with "@indexField" and dynamically return value.
         }
     }
  </code></pre>
  
  <p>The examples left me a bit confused: <a href="https://github.com/Microsoft/TypeScript/wiki/What&#39;s-new-in-TypeScript#decorators" rel="nofollow">https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#decorators</a></p>
  
  <p>What would be the approach, something like this in the model?</p>
  
  <pre><code>function indexField(target, key, descriptor) {
      getObjectInstanceSomehow().setIndexerField(key); //?
  }
  </code></pre>