clearInterval 不适用于句柄
clearInterval not working with handle
我对 clearInterval 函数有疑问。在 Typescript 中,它以红色突出显示 "argument types do not match parameters"。所以我无法注销用户。
这是函数:
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(() => {
// -------^^^^^^^^
我对 clearInterval 函数有疑问。在 Typescript 中,它以红色突出显示 "argument types do not match parameters"。所以我无法注销用户。 这是函数:
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(() => {
// -------^^^^^^^^