【问题标题】:Argument of type 'number' is not assignable to parameter of type 'never' why i am getting this error?'number' 类型的参数不可分配给'never' 类型的参数,为什么我会收到此错误?
【发布时间】:2021-07-30 18:29:51
【问题描述】:
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
 showSecret = false;

logArray = [];

onToggleDetails()
{
this.showSecret = !this.showSecret;
this.logArray.push(this.logArray.length);
}

}

在运行上述代码时,Angular 给出以下错误 错误:src/app/app.component.ts:16:20 - 错误 TS2345:“数字”类型的参数不可分配给“从不”类型的参数。

this.logArray.push(this.logArray.length);

【问题讨论】:

    标签: javascript node.js angular typescript


    【解决方案1】:

    编译器希望您声明 logArray 的类型。尝试以下操作:

    logArray: number[] = [];
    

    让我知道它是否有效:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-30
      • 2017-04-23
      • 2022-11-14
      • 2021-10-26
      • 2020-06-19
      • 2019-10-23
      • 2021-03-01
      • 2020-06-19
      相关资源
      最近更新 更多