clearInterval not working with handle

623 views Asked by At

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;
1

There are 1 answers

0
T.J. Crowder On BEST ANSWER

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(() => {
// -------^^^^^^^^