title: How can I avoid constructor boilerplate with an object-literal TypeScript class constructor?
body: <p>TypeScript has convenient <a href="https://www.typescriptlang.org/docs/handbook/2/classes.html#parameter-properties" rel="nofollow noreferrer">&quot;parameter property&quot;</a> shorthand for class constructors so that I don't have to explicitly define every property, like this:</p>
  <pre><code>class Pizza {
    constructor(
      private sauce: string,
      private cheese: string,
      public radius: number
    ) {}
  }
  </code></pre>
  <p>However, I can also use a constructor that takes an object rather than an argument list (essentially, keyword arguments):</p>
  <pre><code>const pizza = new Pizza({sauce: 'marinara', cheese: 'Venezuelan Beaver', radius: 8})
  </code></pre>
  <p>This syntax has a number of conveniences, not least of which is the ability to use the spread operator to easily copy objects:</p>
  <pre><code>const anotherPizza = new Pizza({...pizza, radius: 10})
  </code></pre>
  <p>But unfortunately it means I can't use the constructor shortcut to avoid all the boilerplate (I think):</p>
  <pre><code>class Pizza {
  
    private sauce: string;
    private cheese: string;
    private radius: number;
  
    constructor({sauce, cheese, radius}: {
        sauce: string,
        cheese: string,
        radius: number
    }) {
      this.sauce = sauce;
      this.cheese = cheese;
      this.radius = radius;
    }
  }
  </code></pre>
  <p>Is there some way to use an object-literal constructor like this and still avoid assigning every property explicitly?</p>