I have a problem when setting the type of a dynamic object in TypeScript because the object that i create has dynamic keys and three that are not.
Here’s how i defined the type for the object:
interface GraphReturns {
[key: string]: {
'%': number,
value: number,
'%Acumulated': number
},
total: number,
'total_%': number,
date: string
}
The errors i get:
- Property ‘total’ of type ‘number’ is not assignable to ‘string’ index type ‘{ ‘%’: number; value: number; ‘%Acumulated’: number; }’
- Property ‘‘total_%’’ of type ‘number’ is not assignable to ‘string’ index type ‘{ ‘%’: number; value: number; ‘%Acumulated’: number; }’
- Property ‘date’ of type ‘string’ is not assignable to ‘string’ index type ‘{ ‘%’: number; value: number; ‘%Acumulated’: number; }’
How can i fix this? Thank you!