TS2345
Argument of type 'number' is not assignable to parameter of type 'TimerHandler'.
Broken Code ❌
function add(a: number, b: number): number {
return a + b;
}
setTimeout(add(1000, 337), 5000);Fixed Code ✔️
There is a mismatch in the expected arguments of a function. The setTimeout function expects the first argument to be a callback function and not the returned value (in this case a number) of a function call:
function add(a: number, b: number): number {
return a + b;
}
setTimeout(() => add(1000, 337), 5000);