简体   繁体   中英

Argument of type 'number' is not assignable to parameter of type 'never' why i am getting this error?

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);
}

}

while running the above code, Angular is giving below error Error: src/app/app.component.ts:16:20 - error TS2345: Argument of type 'number' is not assignable to parameter of type 'never'.

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

The compiler wants you to declare the type of your logArray. Try following:

logArray: number[] = [];

Let me know if it works:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM