Apologies if this is a bit of a dumb question. I've heard a little about call signatures in Typescript, but I don't understand exactly what they do. The Typescript documentation says:
In JavaScript, functions can have properties in addition to being callable. However, the function type expression syntax doesn’t allow for declaring properties. If we want to describe something callable with properties, we can write a call signature in an object type:
type DescribableFunction = {
description: string;
(someArg: number): boolean;
};
function doSomething(fn: DescribableFunction) {
console.log(fn.description + " returned " + fn(6));
}
The documentation doesn't give any examples on how you would actually call doSomething
(nor have pretty much any of the resources I've found on the topic), and I'm confused as to what it means by "something callable with properties". And what exactly does (someArg: number): boolean;
mean? It looks like it's defining a function with a return type of boolean that takes a number argument named someArg
, but passing in a function doesn't do anything. So... what exactly does it mean? Again, I've researched call signatures, but everything I've found pretty much just says "call signatures describe functions in detail", which isn't very helpful. What exactly are call signatures?