title: TypeScript: Generic that is any plain object
body: <blockquote>
    <p><strong>edit</strong> Here is my actual code to explain the issue:</p>
    
    <p><a href="https://gist.github.com/LukasBombach/7bf255392074509147a250b448388518" rel="nofollow noreferrer">https://gist.github.com/LukasBombach/7bf255392074509147a250b448388518</a></p>
  </blockquote>
  
  <p>With TypeScript I want to specify a generic that is any data structure of a plain object</p>
  
  <pre><code>class MyClass&lt;T extends {}&gt; {
    public vars: T;
  
    constructor() {
      this.vars = {};
    }
  }
  </code></pre>
  
  <p>so I can do</p>
  
  <pre><code>interface MyType {
    foo: string;
    bar: number;
  }
  
  new MyClass&lt;MyType&gt;()
  </code></pre>
  
  <p>or</p>
  
  <pre><code>interface MyType {
    baz: string;
    boo: {
      bam: Function;
      bix: number;
    };
  }
  
  new MyClass&lt;MyType&gt;()
  </code></pre>
  
  <p>My proposed implementation up there does not work though, I am getting the error:</p>
  
  <pre><code>class MyClass&lt;T extends {}&gt; {
    public vars: T;
  
    constructor() {
      this.vars = {};
      //   ^^^^
    }
  }
  </code></pre>
  
  <blockquote>
  <pre><code>Type '{}' is not assignable to type 'T'.
    '{}' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.ts(2322)
  </code></pre>
  </blockquote>