title: TypeScript allow for optional arguments - overloading methods
body: <p>I have this method signature on a class:</p>
  
  <pre><code>lock(key: string, opts: any, cb?: LMClientLockCallBack): void;
  </code></pre>
  
  <p>if a user uses it like so:</p>
  
  <pre><code>lock('foo', null, (err,val) =&gt; {
  
  });
  </code></pre>
  
  <p>they will get the right typings. However, if they omit the options argument and do this:</p>
  
  <pre><code>lock('foo', (err,val) =&gt; {
  
  });
  </code></pre>
  
  <p>then <code>tsc</code> sees the callback function as type <code>any</code>, just like this:</p>
  
  <p><a href="https://i.stack.imgur.com/ONspp.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ONspp.png" alt="enter image description here"></a></p>
  
  <p>Is there any way to allow users to avoid passing an empty object or null as the second argument, and shift the callback over?</p>
  
  <p>I tried overloading the method, into two definitions:</p>
  
  <pre><code>  lock(key: string, cb: LMClientLockCallBack, n?: LMClientLockCallBack) : void;
  
    lock(key: string, opts: any, cb?: LMClientLockCallBack) { ... }
  </code></pre>
  
  <p>but it still doesn't compile, there are new problems:</p>
  
  <p><a href="https://i.stack.imgur.com/Lktmo.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Lktmo.png" alt="enter image description here"></a></p>
  
  <p>and if I try this:</p>
  
  <pre><code>  lock(key: string, cb: LMClientLockCallBack) : void;
  
    lock(key: string, opts: any, cb?: LMClientLockCallBack) { ... }
  </code></pre>
  
  <p>I get this:</p>
  
  <p><a href="https://i.stack.imgur.com/rq2ED.png" rel="noreferrer"><img src="https://i.stack.imgur.com/rq2ED.png" alt="enter image description here"></a></p>
  
  <p>Surely there must be a solution to this one?</p>