I'm currently working on writing a debounce function in TypeScript, but I'm feeling uncertain about the type that should be assigned to a variable used with setTimeout
. This is the snippet of my code:
function debounced(func: () => void, wait: number) {
// What should be the type of 'timeout' variable here?
let timeout: any;
return () => {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(() => {
func();
}, wait);
};
}