title: Typescript: index signature on class properties
body: <p>I am getting an error about index signatures when trying to dynamically access my static and instantiated class properties. I've found a lot of people talking about this error online, but I've not yet been able to fix the issue.</p>
  
  <p>I was able to reproduce the issue on a simple class:</p>
  
  <pre><code>interface MyClassInterface {
    name: string;
    getInstanceProperty( propertyName: string ): string;
    getStaticProperty( propertyName: string ): number;
  }
  
  class MyClass implements MyClassInterface {
  
    public name: string;
  
    private static age: number;
  
    public constructor( theName: string, theAge: number ) {
  
      this.name = theName;
      MyClass.age = theAge;
  
    }
  
    public getInstanceProperty( propertyName: string ): string {
  
      return this[propertyName];
      // Typescript error:
      // Element implicitly has an 'any' type because type 'MyClass' has no index signature.
  
    }
  
    public getStaticProperty( propertyName: string ): number {
  
      return MyClass[propertyName];
      // Typescript error:
      // Element implicitly has an 'any' type because type 'typeof MyClass' has no index signature.
  
    }
  
  }
  
  const myClass = new MyClass( "John", 35 );
  
  console.log(
    myClass.getInstanceProperty( "name" ),
    myClass.getStaticProperty( "age" )
  ); // Outputs "John 35" in the console
  </code></pre>
  
  <p>I found that it is possible to avoid the error in getInstanceProperty() by adding a type information inside of the class as follows:</p>
  
  <pre><code>class MyClass implements MyClassInterface {
    [key: string]: any;
  
    // ...
  }
  </code></pre>
  
  <p>Is it possible to add this in the class interface? I haven't managed to do it yet.
  I suppose that I need a similar modification somewhere for the static properties, but I don't know how to do it. Any idea?</p>
  
  <p>I have reproduced this code in the <a href="http://www.typescriptlang.org/play/index.html#src=interface%20MyClassInterface%20%7B%0D%0A%20%20name%3A%20string%3B%0D%0A%20%20getInstanceProperty%3A%20any%3B%0D%0A%20%20getStaticProperty%3A%20any%3B%0D%0A%7D%0D%0A%0D%0Aclass%20MyClass%20implements%20MyClassInterface%20%7B%0D%0A%20%20%5Bkey%3A%20string%5D%3A%20any%3B%0D%0A%0D%0A%20%20public%20name%3A%20string%3B%0D%0A%20%20%0D%0A%20%20private%20static%20age%3A%20number%3B%0D%0A%0D%0A%20%20public%20constructor(%20theName%3A%20string%2C%20theAge%3A%20number%20)%20%7B%0D%0A%0D%0A%20%20%20%20this.name%20%3D%20theName%3B%0D%0A%20%20%20%20MyClass.age%20%3D%20theAge%3B%0D%0A%0D%0A%20%20%7D%0D%0A%0D%0A%20%20public%20getInstanceProperty(%20propertyName%3A%20string%20)%3A%20string%20%7B%0D%0A%0D%0A%20%20%20%20return%20this%5BpropertyName%5D%3B%0D%0A%0D%0A%20%20%7D%0D%0A%0D%0A%20%20public%20getStaticProperty(%20propertyName%3A%20string%20)%3A%20number%20%7B%0D%0A%0D%0A%20%20%20%20return%20MyClass%5BpropertyName%5D%3B%0D%0A%0D%0A%20%20%7D%0D%0A%0D%0A%7D%0D%0A%0D%0Aconst%20myClass%20%3D%20new%20MyClass(%20%22John%22%2C%2035%20)%3B%0D%0A%0D%0Aconsole.log(%0D%0A%20%20myClass.getInstanceProperty(%20%22name%22%20)%2C%0D%0A%20%20myClass.getStaticProperty(%20%22age%22%20)%0D%0A)%3B" rel="noreferrer">TypeScript Playground</a>. You just need to enable the noImplicitAny option to show the errors.</p>
  
  <p>Many thanks!</p>