title: How can I prevent typescript from throwing errors on an object that references another object's method
body: <p>So I have an entity component system, and basically when you add a component object to an entity its binds all the methods to the entity object.</p>
  
  <pre class="lang-js prettyprint-override"><code>  class Component {
       constructor(){}
       componentMethod() {
         console.log('component method called');
       }
    }
    class Entity {
       constructor(){}
       addComponent(component) {
          Object.getOwnProperties(component).forEach(p =&gt; {
             // some logic make sure its not constructor or duplicate in entity
             this[p] = component[p].bind(component);
          })
       }
     }
     const component = new Component();
     const entity = new Entity();
     // works fine
     entity.addComponent(component);
     entity.componentMethod(); // works if I type entity as any but typescript is throwing an error when I type entity as Entity
  </code></pre>
  
  <p>Error</p>
  
  <pre><code>Error:() TS2339: Property 'componentMethod' does not exist on type 'Entity'.
  </code></pre>