Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript TypeScript-f.e.设置间隔是什么类型_Javascript_Angular_Typescript_Typescript2.0 - Fatal编程技术网

Javascript TypeScript-f.e.设置间隔是什么类型

Javascript TypeScript-f.e.设置间隔是什么类型,javascript,angular,typescript,typescript2.0,Javascript,Angular,Typescript,Typescript2.0,如果我想为一个变量分配一个类型,该变量稍后将被分配一个setInterval,如下所示: this.autoSaveInterval = setInterval(function(){ if(this.car.id){ this.save(); } else{ this.create(); } }.bind(this), 50000); 应该为该变量指定什么类型。autosaveInterval VARAB

如果我想为一个变量分配一个类型,该变量稍后将被分配一个setInterval,如下所示:

this.autoSaveInterval = setInterval(function(){
      if(this.car.id){
        this.save();
      }
      else{
        this.create();
      }
    }.bind(this), 50000);

应该为该变量指定什么类型。autosaveInterval VARABLE?

使用typeof运算符查找如下任何变量的数据类型:

typeof是放在单个操作数之前的一元运算符 可以是任何类型的。它的值是一个字符串,用于指定 操作数的类型

var variable1=“你好”;
var自存区间;
this.autoSaveInterval=setInterval(函数(){
如果(本车id){
这是save();
}
否则{
这个。create();
}
}.bind(本),50000);
控制台日志(“第一个:+类型(变量1))
console.log(“第二个:+typeof(autoSaveInterval))
类型是数字

private autoSaveInterval:number=setInterval(()=>{
console.log('123');
}, 5000);

类型取决于要使用的函数有2个重载,返回类型在红色边界框中标记:

要使用返回数字的,请使用:

window.setInterval(...)

迟到了,但是最好的类型(特别是因为类型是不透明的,我们只关心可以稍后将其传递给
clearInterval()
)可能是自动推断的类型,例如:

ReturnType<typeof setInterval>
ReturnType

我相信它的NodeJS.Timeout和widow.setInterval是数字:

const nodeInterval: NodeJS.Timeout = setInterval(() => {
  // do something
}, 1000);

const windowInterval: number = window.setInterval(() => {
  // do something
}, 1000);

公共自动保存间隔:编号;您不需要指定类型
autoSaveInterval
将根据
setInterval
调用的返回值推断其类型。在浏览器平台中,这是编号,但在node.js中,这是一个Timer@gfels因为setInterval返回表示所设置计时器的ID值的值。您可以将此值与clearInterval()方法一起使用以取消计时器。它不是一个函数,因为你不是在给它赋值函数处理程序,而是在给它赋值函数的结果/返回值。“数字”不起作用,特别是在安古拉里,我加入了这个党,数字对我也不起作用,谢谢!!最干净的解决问题的方法,适用于所有环境。您是否可以共享您获得此参考的网站或书籍?谢谢。您好,这不是一本书,如果您使用visual studio并搜索实现,您可以找到它。