TypeScript - what type is f.e. setInterval
The type depends on which function you are going to use there are 2 overloads, the return type is marked in red bounding-box :
In order to use the one which returns number, please use :
window.setInterval(...)
The type is number;
private autoSaveInterval: number = setInterval(() => {
console.log('123');
}, 5000);
Late to the party, but the best type (especially since the type is opaque, we only care that we can pass it to clearInterval()
later) might be the automatically deduced one, ie. something like:
ReturnType<typeof setInterval>
I believe its NodeJS.Timeout and widow.setInterval is number:
const nodeInterval: NodeJS.Timeout = setInterval(() => {
// do something
}, 1000);
const windowInterval: number = window.setInterval(() => {
// do something
}, 1000);