Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
347 views
in Technique[技术] by (71.8m points)

Angular error Type string is not assignable to type never

I am new to Angular, Can someone please help me out with this issue here.

export class PersonComponent implements OnInit {

  Schools= [];
  
  constructor() { 
  }

  ngOnInit(): void {

  this.Schools= [
    {Name : "ABD Schoool" , Title : "Colarado"},
    {Name : "CC School" , Title : "Texas"}
  ];

  }

}

However, I am getting an error stating 'Type string is not assignable to type never'. What does this mean and how can I solve this?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try:

  schools: any[] = [];

Without defining the array type, it's by default of type never.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...