title: How to create Class dynamically in a proper way in Typescript?
body: <p>I am trying to migrate my app to typescript. I have kind of a base class that is my base library object. My classes created dependent on the base class. Below is a glimpse of my problem.</p>
  
  <p>Below code works but autocomplete doesn't work. Couldn't figure out what should be defined for the type of <code>Model</code>.</p>
  
  <pre class="lang-js prettyprint-override"><code>const map = new WeakMap();
  function weakRef&lt;T&gt;(context: T): T {
    // @ts-ignore
    if (!map.has(context)) { map.set(context, {}); }
    // @ts-ignore
    return map.get(context);
  }
  function getModel(provider: Provider) {
    return class Model {
      getSomething(key: string) {
        return weakRef(provider).configuration(key);
      }
    };
  }
  
  class Provider {
    configuration: (key: string) =&gt; string;
    constructor() {
      weakRef(this).configuration = (key: string) =&gt; {
        return key;
      };
      weakRef(this).Model = getModel(this);
    }
    get Model(): any {
      return weakRef(this).Model;
    }
    set Model(model: any) {
      weakRef(this).Model = model;
    }
  }
  
  const provider = new Provider();
  const obj = new (provider.Model)();
  console.log(obj.getSomething('test')); // This works, but autocomplete doesn't
  
  </code></pre>
  
  <p>I don't want to pass provider to the constructor in base model.
  Any help is appreciated, thanks.</p>