The best outcome is that we enforce that the function which is returned by the throttle function has exactly the same signature as func, regardless of how many parameters func takes. Using incorrect types or the wrong number of parameters when calling the wrapped function should result in a compiler error. function throttle(func: Function, timeout: any) { let ready = true; return (...args: any) => { if (!ready) { return; } ready = false; func(...args); setTimeout(() => { ready = true; }, timeout); }; } function sayHello(name: string): void { console.log(`Hello ${name}`); } const throttledSayHello = throttle(sayHello, 1000); // this should result in compilation failure throttledSayHello(1337); // so should this const throttledSayHello2 = throttle(sayHello, "breakstuff"); Via Active questions tagged javascript - Stack Overflow https://ift.tt/8E9s0g2
A site where you can share knowledge