Javascript 错误TS2356表示数字类型变量必须是类型为';编号';

Javascript 错误TS2356表示数字类型变量必须是类型为';编号';,javascript,typescript,setinterval,Javascript,Typescript,Setinterval,这就是我的类定义: timeLeft: Number; constructor() { this.timeLeft = 60; } start() { console.log(typeof(this.timeLeft)); // prints out 'number' setInterval(() => { this.timeLeft--; // error TS2356 occurs here console.log(th

这就是我的类定义:

timeLeft: Number;

constructor() { 
    this.timeLeft = 60;
  }

  start() {
    console.log(typeof(this.timeLeft)); // prints out 'number'

    setInterval(() => {

      this.timeLeft--; // error TS2356 occurs here
      console.log(this.timeLeft);

    }, 1000);
  }

  ngOnInit() {}
控制台:

错误TS2356:算术操作数必须为“any”、“number”或枚举类型


正如菲尔在评论部分提到的,最好使用“number”而不是“number”“Number”指的是在JavaScript代码中几乎从未正确使用过的非基本装箱对象。
参考:

正如菲尔在评论部分提到的,最好使用“数字”而不是“数字”“Number”指的是在JavaScript代码中几乎从未正确使用过的非基本装箱对象。
参考:

我对Typescript非常糟糕,但粗略地看一下文档表明,
timeLeft
应该是
number
类型,而不是
number
我对Typescript非常糟糕,但是粗略地看一下文档表明
timeLeft
应该是
number
类型,非
编号