I'm new in typescript and I couldn't find the answer so I would like to ask how can I access to custom type value?
Let's say I have my custom type like this
type Notes = {
5: number;
10: number;
20: number;
}
and I create instance like this
const availableNotes: Notes = {
5: 10,
10: 20,
20: 40,
};
I tried to access the values of availableNotes
like this
const noteTypes: string[] = Object.keys(availableNotes);
for(let i = 0; i < noteTypes.length; i++) {
const value = availableNotes[noteTypes[i]]
... // Some logic
}
And this is an error
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ '5': number; '10': number; '20': number; }'.
No index signature with a parameter of type 'string' was found on type '{ '5': number; '10': number; '20': number; }'
Appreciate your help!