I am currently encountering a typescript syntax error in my project that is indicating the need to define the prodStatus
variable...
const products = {
1: {isUpdating: false, qty: 2},
2: {isUpdating: true, qty: 4}
}
const updatingProducts: Array<{id: number; prodStatus: {isUpdating: boolean; qty: number}}> = [];
Object.entries(products).forEach(([prodId, prodStatus]) => {
if (prodStatus.isUpdating) {
updatingProducts.push({id: Number(prodId), prodStatus: prodStatus});
}
});
The error is occurring at both the if(prodStatus.isUpdating)
condition and when trying to access the key prodStatus
in the push
method. This could be due to the fact that I am importing the variable products
in my actual project code, and Typescript requires a defined type for prodStatus
?
Does anyone have insights on how to assign a type to the variable [prodId, prodStatus]
?
NOTE: In the file where I import the products
variable, it has this format (in ReactJS)...
const products = useRef<{[key: string]: {isUpdating: boolean; qty: number}}>({});
UPDATE: I have attempted a solution and have included an updated screenshot of the error... https://i.sstatic.net/J1bkK.png