title: how to remove properties and promisify method via mapped type in TypeScript
body: <p>Here is the code</p>
  
  <pre><code>class A {
      x = 0;
      y = 0;
      visible = false;
      render() {
          return 1;
      }
  }
  
  type RemoveProperties&lt;T&gt; = {
      readonly [P in keyof T]: T[P] extends Function ? T[P] : never//;
  };
  
  type JustMethodKeys&lt;T&gt; = ({ [P in keyof T]: T[P] extends Function ? P : never })[keyof T];
  type JustMethods&lt;T&gt; = Pick&lt;T, JustMethodKeys&lt;T&gt;&gt;;
  
  
  type IsValidArg&lt;T&gt; = T extends object ? keyof T extends never ? false : true : true;
  
  type Promisified&lt;T extends Function&gt; =
      T extends (...args: any[]) =&gt; Promise&lt;any&gt; ? T : (
          T extends (a: infer A, b: infer B, c: infer C, d: infer D, e: infer E, f: infer F, g: infer G, h: infer H, i: infer I, j: infer J) =&gt; infer R ? (
              IsValidArg&lt;J&gt; extends true ? (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, i: I, j: J) =&gt; Promise&lt;R&gt; :
              IsValidArg&lt;I&gt; extends true ? (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, i: I) =&gt; Promise&lt;R&gt; :
              IsValidArg&lt;H&gt; extends true ? (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H) =&gt; Promise&lt;R&gt; :
              IsValidArg&lt;G&gt; extends true ? (a: A, b: B, c: C, d: D, e: E, f: F, g: G) =&gt; Promise&lt;R&gt; :
              IsValidArg&lt;F&gt; extends true ? (a: A, b: B, c: C, d: D, e: E, f: F) =&gt; Promise&lt;R&gt; :
              IsValidArg&lt;E&gt; extends true ? (a: A, b: B, c: C, d: D, e: E) =&gt; Promise&lt;R&gt; :
              IsValidArg&lt;D&gt; extends true ? (a: A, b: B, c: C, d: D) =&gt; Promise&lt;R&gt; :
              IsValidArg&lt;C&gt; extends true ? (a: A, b: B, c: C) =&gt; Promise&lt;R&gt; :
              IsValidArg&lt;B&gt; extends true ? (a: A, b: B) =&gt; Promise&lt;R&gt; :
              IsValidArg&lt;A&gt; extends true ? (a: A) =&gt; Promise&lt;R&gt; :
              () =&gt; Promise&lt;R&gt;
          ) : never
      );
  
  
  
  var a = new A() as JustMethods&lt;A&gt;  // I want to JustMethod &amp;&amp; Promisified
  a.visible // error
  var b = a.render() // b should be Promise&lt;number&gt;
  </code></pre>
  
  <p>How to implement it ? I want to remove visible and promisify render method , how to composite Promisified and JustMethods ?</p>
  
  <p>How to implement it ? I want to remove visible and promisify render method , how to composite Promisified and JustMethods ?</p>