[英]. WHY DO I GET THE FOLLOWING ERROR? Type 'Photo' is not assignable to type 'never'
enter image description here在此处输入图像描述
export class PhotoListComponent implements OnInit {
photos = [];
constructor(private photoService: PhotoService) { }
ngOnInit() {
this.photoService.getPhotos()
.subscribe(
res => {
this.photos = res;
},
err => console.log(err)
)
}
}
photos = [];
Since you havn't specified a type here, typescript needs to infer it.由于您没有在此处指定类型,因此 typescript 需要推断它。 But with no clues about what this array is supposed to contain, typescript infers the type to be never[]
.但是没有关于这个数组应该包含什么的线索, typescript 推断类型为never[]
。 Then later on, when you try to assign something else to it, you get a type error.稍后,当您尝试为其分配其他内容时,您会收到类型错误。
Change it to:将其更改为:
photos: Photo[] = [];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.