I'm trying to work with the same variable to handle the return value of setInterval()
and then pass it as an argument to clearInterval()
in TypeScript. The issue I'm facing is that setInterval()
gives back a NodeJS.Timer
while clearInterval()
expects a number
.
This is how I want my code to be structured:
itemCooldownTimer: NodeJS.Timer | undefined;
this.itemCooldownTimer = setInterval(this.tickCooldown, 1000);
This is how I intend to clear the interval:
clearInterval(this.itemCooldownTimer);