I have a problem with clearInterval function. In Typescript it is highlighted red "argument types do not match parameters". So I am unable to log out user. Here is the function:
private check() {
if (this.isLogged) {
var timer = setInterval(() => {
if(this.Expiration < new Date()) {
this.signOut.emit(true);
clearInterval(timer);
}
}, 3000);
}
}
Can I do this instead of clearInterval ?
timer = null;
No. Doing that would have no effect on the interval timer. It just sets the
timer
variable tonull
.Make it match. One would have expected type inference to be correctly assigning
timer
the typenumber
, but the error you've quoted suggests that's not happening. You can do it explicitly: