I'm encountering some difficulties while attempting to access my object property in TypeScript:
const sum = (type: string) => {
return {
status: 'Sum',
value: data?[type].sum,
};
};
sum('first')
Here is a glimpse of my data structure:
data: {
first: {
sum: 15
},
second: {
sum: 515
}
}
Upon trying to access the property, I am presented with
TS2339: Property 'sum' does not exist on type 'string[]'.
Why is this happening and what is the solution to this issue?