'javascript typescript, foreach loop error - x has no call signatures
I am getting an error on my forEach loop in javascript using typescript.
This expression is not callable. Type 'TradeData[]' has no call signatures.
using redux I call an api to download data in this format
export interface TradeData {
id: number;
filedate: Date;
poffic: string;
pacct: string;
quantity: number;
sector: string;
psdsC1: string;
name: string;
bbsymbol: string;
last_price: number;
deltasettlement: number;
}
then I use reduce to group that data by a certain property
React.useEffect(() => {
const doGetTrades = async () => {
const unansweredQuestions = await getTrades();
dispatch(gotTradesAction(unansweredQuestions));
const result = unansweredQuestions.reduce<Record<string, TradeData[]>>(
(groupedAccounts, trade) => {
const account = trade.bbsymbol;
if (groupedAccounts[account] == null) {
groupedAccounts[account] = [];
}
groupedAccounts[account].push(trade);
return groupedAccounts;
},
{} as Record<string, TradeData[]>
);
console.log("result");
console.log(result);
console.log("foreach");
result.forEach(function (value) {
console.log(value);
});
};
doGetTrades();
now I am trying to cycle through that returned array "result". First with a simple foreach loop, and logging to console window. I am getting an error which I believe is due to typescript but I do not know the proper way to define.
Can someone please assist to show me how to handle?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
