interface F1 {
(a, b): any;
}
interface F2 {
(a): any;
}
type F3 = F1 | F2;
const f: F3 = (a) => {
console.log(123, a);
}
f(1) // Error
I'm stumbled upon one of the mysterious problems in TypeScript (3.1.4). While I call f(), the compiler says Cannot invoke an expression whose type lacks a call signature. Type 'F3' has no compatible call signatures. [2349].
This is even strange since all of the above code works fine until that f(1).
Am I missing something here? If any, how can I give the union typed function typing?
I know I can do something like this
interface T {
(a, b): any;
(a): any;
}
But then I have to define function in such a way
function (a, b?) {
}
which I don't like that much. Any help/feedback would be appreciated.