Я пишу этот код, чтобы получить сумму о диапазоне дат, но я столкнулся с этой проблемой
Operator '>' cannot be applied to types 'Iterable' and 'Date'.
Вот мой код
export function getTotalYearCosts(valueItem: ValueItem, allCosts: Map<string, Costs>): TotalCosts {
const totalYearCosts = { planned: 0, actual: 0 };
const test = allCosts.map(({created}) => created);
const Q1 = new Date('2018-01-01');
const Q2 = new Date('2018-04-01');
totalYearCosts.actual = valueItem.actualCostIds
.map(costId => allCosts.get(costId, emptyCosts()).costs)
.filter(costs => test > Q1 && test < Q2)
.reduce((reduction, costs) => reduction + costs, 0);
totalYearCosts.planned = valueItem.plannedCostIds
.map(costId => allCosts.get(costId, emptyCosts()).costs)
.reduce((reduction, costs) => reduction + costs, 0);
return totalYearCosts;
}
Интерфейс затрат
export interface Costs {
id: string;
created: Date;
costs: number;
// costType: number;
type: number;
reference: string;
comment: string;
}
Что вы предлагаете мне сделать в этом случае, чтобы сравнить дату и суммировать затраты по диапазону дат?
Что вы ожидаете от test ?
У меня есть затраты, такие как объект интерфейса, и затраты имеют дату, когда были созданы. Я просто хочу, чтобы, если затраты (тест) больше этого Q1 и меньше Q2, уменьшите эту функцию + затраты. Я обновлю код, чтобы увидеть интерфейс затрат
@bugs Вы можете мне в этом помочь?



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Я исправил это.
export function getTotalYearCosts(valueItem: ValueItem, allCosts: Map<string, Costs>): ActualCosts {
const totalYearCosts = { actual: 0, planned: 0, Q1: 0, Q2: 0, Q3: 0, Q4: 0 };
const iter = allCosts[Symbol.iterator]();
for (let i = 0; i < valueItem.actualCostIds.length; i++) {
const costID = valueItem.actualCostIds[i];
if (allCosts.get(costID).created.getMonth() < 3 && allCosts.get(costID).created.getMonth() >= 0 ) {
totalYearCosts.actual += allCosts.get(costID).costs;
totalYearCosts.Q1 += allCosts.get(costID).costs;
allCosts.map(({created}) => created);не возвращаетDate, и ошибка говорит вам, что вы не можете сравнить дату с чем-то еще с оператором>