I am new to typescript. While I was learning signatures, I came across this error. I declared a type with function as shown
CodePudding user response:
You need to mutate printToConsole
and add desc
property.
type GreetFunction = {
desc: string;
(x: string): void;
};
function greeter(fn: GreetFunction) {
fn("Hello");
}
function printToConsole(a: string) {
console.log(a);
}
printToConsole.desc = 'df' // <--------------- add desc property
greeter(printToConsole); // ok
This is the rare case when TypeScript tracks mutations. Please see similar question