I have this method signature on a class:
lock(key: string, opts: any, cb?: LMClientLockCallBack): void;
if a user uses it like so:
lock('foo', null, (err,val) => {
});
they will get the right typings. However, if they omit the options argument and do this:
lock('foo', (err,val) => {
});
then tsc
sees the callback function as type any
, just like this:
Is there any way to allow users to avoid passing an empty object or null as the second argument, and shift the callback over?
I tried overloading the method, into two definitions:
lock(key: string, cb: LMClientLockCallBack, n?: LMClientLockCallBack) : void;
lock(key: string, opts: any, cb?: LMClientLockCallBack) { ... }
but it still doesn't compile, there are new problems:
and if I try this:
lock(key: string, cb: LMClientLockCallBack) : void;
lock(key: string, opts: any, cb?: LMClientLockCallBack) { ... }
I get this:
Surely there must be a solution to this one?