title: Dynamic TypeScript Typing
body: <p>Is there any way to have dynamic object properties in a TypeScript class, and add dynamic Typings in for TypeScript?  </p>
  
  <p>I have seen similar questions but none with a complete example like this - </p>
  
  <pre><code>interface IHasObjectName {
     objectName: string;
  }
  
  class example&lt;A extends IHasObjectName, B  extends IHasObjectName&gt; {
  
      constructor(a: A, b: B) {
          this[a.objectName] = function() { return a; };
          this[b.objectName] = function() { return b; }
      }
  }
  
  class Cat implements IHasObjectName {
      objectName: string = "";
  }
  
  class Dog implements IHasObjectName {
      objectName: string = "";
  }
  
  let cat = new Cat();
  cat.objectName = "Cat";
  
  let dog = new Dog();
  dog.objectName = "Dog";
  
  let test = new example&lt;Cat,Dog&gt;(cat, dog);
  
  // ??? TYPESCRIPT DOESN'T KNOW ABOUT THESE DYNAMIC PROPERTIES
  // HOW DO I MAKE THIS WORK?
  let d = test.Dog();
  let c = test.Cat();
  
  // I know I could access like this 
  // let d = test["Dog"](); 
  // but I want to access like function and have it typed
  </code></pre>