title: Cleanest way to pass optional parameters in typescript
body: <p>I am using the &quot;mongodb&quot; driver for nodejs. I am trying to add an optional parameter for ttl to this existing method:</p>
  <pre><code>public async createIndex(index: any, unique: boolean): Promise&lt;void&gt; {
      await this.collection.createIndex(index, { unique });
  }
  </code></pre>
  <p>Is there a more elegant way to do it than this:</p>
  <pre><code>public async createIndex(index: any, unique: boolean, ttl: number): Promise&lt;void&gt; {
      await ttl ? this.collection.createIndex(index, { unique, ttl }) : this.collection.createIndex(index, { unique });
  }
  </code></pre>
  <p>I read that <a href="https://medium.com/@kgrvr/typescript-functions-optional-parameters-b245e7a06d7d" rel="nofollow noreferrer">passing null to an optional parameter</a> can make it act weirdly.</p>