While delving into the Typescript documentation, I came across the concept of type alias and found an interesting example here.
type DescribableFunction = {
description: string;
(someArg: number): boolean;
};
function doSomething(fn: DescribableFunction) {
console.log(fn.description + " returned " + fn(6));
}
However, simply running this example doesn't output anything because the doSomething function is not invoked anywhere. To make the function property in the DescribableFunction type more descriptive, I attempted to modify it like this, although it proved ineffective.
type DescribableFunction = {
description: string;
(someArg: number): boolean;
};
function doSomething(fn: DescribableFunction) {
console.log(fn.description + " returned " + fn(6));
}
const new_fn: DescribableFunction = {
description: "test",
() { // what should I include here?
return true;
},
};
doSomething(new_fn);