title: Typescript enforce object destructuring
body: <p>I'm trying to write a class that uses its generic type as the object to be destructured to enforce only those fields to be used.</p>
  <p>Is it possible to use typescript to indicate that an object must be destructured, and work with its fields?</p>
  <pre><code>class A&lt;T&gt; {
    doSomething ( { destructured object }: T) {
      // work with destructured T...
    }
  }
  </code></pre>
  <p>For example, id like an object with this interface to be inserted in a database:</p>
  <pre><code>interface AnInterface { a: number; b: string; }
  </code></pre>
  <p>So I create this generic class</p>
  <pre><code>Class CRUDLService&lt;T&gt; {
    create( { destructured object }: T ) {
      // Insert object with the fields of T only, not any other
    }
  }
  </code></pre>
  <p>So I can create a generic service, for example:</p>
  <pre><code>const anInterfaceService = new CRUDLService&lt;AnInterface&gt;();
  </code></pre>
  <p>This way I could try to ensure that whenever anInterfaceService.create is called, only the right fields are being used.</p>
  <p>The way I'm doing it right now doesn't take advantage of typescript, instead when you create these generic classes, you need to specify an array of strings that represent the fields being extracted from the object for the operation. ie:</p>
  <pre><code>const createFields = ['a', 'b']; 
  </code></pre>