【发布时间】:2021-06-23 04:24:50
【问题描述】:
我创建了一个转换管道来减少对象列表
export class SumPipe implements PipeTransform {
transform(items: ListCount[], attr: string): number {
return items.reduce((a, b) => a + b[attr], 0);
}
}
这是 ListCount 的模型:
export interface ListCount {
centre?: string;
cause?: string;
Time?: number;
}
但我有这个错误:
error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'ListCount'
请帮忙
【问题讨论】:
-
为什么这被关闭为拼写错误/不可重现?如果它是重复的,我不会感到惊讶,但除此之外,这是一个完全有效的问题。
标签: angular typescript pipe reduce