While going through this documentation, I found myself puzzled by the concept of having a parameter that can be both an object and a function in JavaScript.
type DescribableFunction = {
description: string;
(a: any): boolean;
};
function doSomething(fn: DescribableFunction) {
console.log(fn.description + " returned " + fn(6));
};
doSomething((()=>false)); // Argument of type '() => false' is not assignable to parameter of type 'DescribableFunction'. Property 'description' is missing in type '() => false' but required in type 'DescribableFunction'.
doSomething({description: 'test'}); // fn is not a function.
The example above raises the question: how could the parameter fn
serve as both an object and a function simultaneously..?