gpt4 book ai didi

javascript - clearInterval 不适用于句柄

转载 作者:行者123 更新时间:2023-12-02 13:47:50 25 4
gpt4 key购买 nike

我在使用clearInterval函数时遇到问题。在 Typescript 中,它以红色突出显示“参数类型与参数不匹配”。所以我无法注销用户。这是函数:

private check() {
if (this.isLogged) {
var timer = setInterval(() => {
if(this.Expiration < new Date()) {
this.signOut.emit(true);
clearInterval(timer);
}
}, 3000);
}
}

我可以用这个来代替clearInterval吗?

timer = null;

最佳答案

Can I do this instead of clearInterval ?

没有。这样做不会对间隔计时器产生影响。它只是将 timer 变量设置为 null

In Typescript it is highlighted red "argument types do not match parameters".

使其匹配。人们会想到type inference正确分配 timer 类型 number,但您引用的错误表明这种情况没有发生。您可以明确地执行此操作:

var timer : number = setInterval(() => {
// -------^^^^^^^^

关于javascript - clearInterval 不适用于句柄,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41240259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com