我有一个变量,它是类型为Club的数组。一个函数正在填充此变量。
clubs: [Club];
功能:
this.authService.getAllClubs().subscribe(
clubs => {
var result = [];
if(clubs.length > 0) {
for (const club of clubs) {
let c = club.club;
let b = new Club(c.id, c.name, false);
result.push(b);
}
}
this.clubs = result;
}
);
但是我在此代码上收到以下错误:(this.clubs = result;)
Property '0' is missing in type 'any[]' but required in type '[Club]'.ts(2741)
我怎样才能与类型俱乐部组成一个数组?我在这里做错了什么?
你应该写组件
您似乎在混淆两种不同的类型:
[Club]
: is a tuple with only one element, a ClubClub[]
: is an array of Club elements您应该将结果输入为正确的内容并修复类型,以使其正常工作