title: Destructured parameter properties in constructor
body: <p>Typescript allows parameter properties</p>
  
  <pre><code>class ParameterProperty {
    constructor(private member: number) {}
  }
  </code></pre>
  
  <p>The above creates a class with private member <code>member</code>, the constructor sets <code>this.member</code> to the  first argument of the constructor.</p>
  
  <p>But there is no equivalent for 'named parameters' via destructuring.</p>
  
  <pre><code>interface DestructedOptions {
    prefix: string;
    suffix: string;
  }
  
  class Destructed {
    constructor({private prefix, private suffix}: DestructedOptions) {}
  }
  </code></pre>
  
  <p>The above doesn't work, you have to do something  like this:</p>
  
  <pre><code>class Destructed {
    private prefix: string
    private suffix: string
    constructor({prefix, suffix}: DestructedOptions) {
      this.prefix = prefix;
      this.suffix = suffix;
    }
  }
  </code></pre>
  
  <p>which is really verbose and requires updates to three places when adding a new property to <code>DestructuredOptions</code>. I tried something similar, using mapped properties</p>
  
  <pre><code>class Destructed {
    private [P in keyof DestructedOptions]: T[DestructedOptions];
    constructor(opts: DestructedOptions) {
      Object.assign(this, opts)
    }
  }
  </code></pre>
  
  <p>Only to find out that mapped properties can only be used in Types, not interfaces or classes. I don't like this option anyway since it copies everything from opts, I would really want something like this:</p>
  
  <pre><code>class Destructed {
    constructor(opts: DestructedOptions) {
      for (let key in keyof DestructedOptions) {
        this[key] = opts[key];
      }
    }
  }
  </code></pre>
  
  <p>But of course typescript doesn't let you get runtime values from Types.</p>