I would be glad if anyone could explain to me why when I want to get a sum of amounts I always get an error something like: "Operator + cannot be applied to types '{ data: string, amount: number}' or any other type.
(如果有人能向我解释为什么我想得到一定数量的总和,我总是很高兴,但是总会出现类似以下错误: “运算符+无法应用于类型'{数据:字符串,数量:数字}'或任何其他类型类型。)
const payments = [
[
{ data: '11/12/19', amount: 1000 },
],
[
{ data: '11/01/20', amount: 1000 },
{ data: '12/01/19', amount: 1000 },
],
[],
[
{ data: '11/02/20', amount: 1000 },
{ data: '12/02/19', amount: 1000 },
{ data: '12/02/19', amount: 1000 },
],
[],
[],
[],
[],
[],
[],
[],
[],
];
const acc = new Array(12).fill([]);
acc.forEach((value, index, arr) => {
if (payments[index] === undefined) { return []; }
console.log(payments[index]);
const total = payments[index].reduce((acc, value) => acc + value.amount)
});
ask by Valary o translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…