title: How to create function that returns mixin function in TypeScript?
body: <p>I try to convert <code>Polymer.dedupingMixin</code> ES6 function to TypeScript. I don't sure it's possible or not.</p>
  
  <p><a href="https://github.com/Polymer/polymer/blob/v2.0.2/lib/utils/mixin.html" rel="nofollow noreferrer">https://github.com/Polymer/polymer/blob/v2.0.2/lib/utils/mixin.html</a></p>
  
  <p>Normally, TypeScript 2.2+ can work correctly for basic mixin function like the following code.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>type IConstructable = new (...args: any[]) =&gt; object;
  
  function extendClass&lt;T extends IConstructable&gt;(baseClass: T) {
      return class extends baseClass {
          instanceMethod_DynamicClass() { }
          static staticMethod_DynamicClass() { }
      }
  }
  
  class Test {
      instanceMethod_TestClass() { }
      static staticMethod_TestClass() { }
  }
  
  var d3 = extendClass(Test);
  d3.staticMethod_DynamicClass();
  d3.staticMethod_TestClass();
  
  var d4 = new d3();
  d4.instanceMethod_DynamicClass();
  d4.instanceMethod_TestClass();</code></pre>
  </div>
  </div>
  </p>
  
  <p>I try to create some function like this declaration fuction.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>declare function extendClass&lt;T extends IConstructable&gt;(baseClass: T): {
      new (...args: any[]): {
          instanceMethod_DynamicClass(): void;
      };
      staticMethod_DynamicClass(): void;
  } &amp; T;</code></pre>
  </div>
  </div>
  </p>
  
  <p>My TypeScript code looks like the following code. It doesn't work correctly. I try modify generic type in many places. But it's still not work.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>interface IConstructable&lt;T&gt; {
      new(...args: any[]): T;
  }
  
  function extendClass&lt;T extends IConstructable&lt;T&gt;, TExtended extends IConstructable&lt;TExtended&gt;&gt;(mixin: (base: T) =&gt; TExtended &amp; T) {
      return function &lt;T, TExtended&gt;(base: T) {
          return mixin(base);
      };
  }
  
  class Test {
      instanceMethod_TestClass() { }
      static staticMethod_TestClass() { }
  }
  
  class Test2 {
      instanceMethod_TestClass() { }
      static staticMethod_TestClass() { }
  }
  
  var propEffect = extendClass(superClass =&gt; {    
      return class internalClass extends superClass {
          instanceMethod_ExtendedClass() { }
          static staticMethod_ExtendedClass() { }
      }
  });
  
  var d3 = propEffect(Test) ;
  d3.staticMethod_ExtendedClass();
  d3.staticMethod_TestClass();
  
  var d4 = new d3();
  d4.instanceMethod_ExtendedClass();
  d4.instanceMethod_TestClass();</code></pre>
  </div>
  </div>
  </p>