Reputation: 573
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;
Upvotes: 0
Views: 633
Reputation: 1074238
Can I do this instead of clearInterval ?
No. Doing that would have no effect on the interval timer. It just sets the timer
variable to null
.
In Typescript it is highlighted red "argument types do not match parameters".
Make it match. One would have expected type inference to be correctly assigning timer
the type number
, but the error you've quoted suggests that's not happening. You can do it explicitly:
var timer : number = setInterval(() => {
// -------^^^^^^^^
Upvotes: 2