title: Typescript - Conditional property of object
body: <p>I have the following object to which I wish to have a conditional property:</p>
  
  <pre><code>{ name: this.username, DOB: new Date(this.inputDate)}
  </code></pre>
  
  <p>Say, I wish to add a third property called gender if the user has specified their gender. What would the proper syntax for the following be:</p>
  
  <pre><code>{ name: this.username, DOB: new Date(this.inputDate), if(this.userGender) gender: this.userGender}
  </code></pre>
  
  <p>P.S. I <strong>do not</strong> wish to have the <code>gender</code> property in my object if there is no value along with it. So how can I only create the property if the condition is satisfied?</p>