I'm converting my react app from JavaScript to TypeScript trying to figure out how I can address the following errors
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Schedule'. No index signature with a parameter of type 'string' was found on type 'Schedule'.
This is the code...
export interface Schedule {
display: Display;
monday: Day;
tuesday: Day;
wednesday: Day;
thursday: Day;
friday: Day;
saturday: Day;
sunday: Day;
}
export interface Diary {
schedule: Schedule;
appointments: Array<Appointment>;
}
// ...
const dayKey: string = 'monday'
const day: Day = diary.schedule[dayKey] // <-- Here is the error
// ...
Previously as the data structure I was working with in JavaScript was just json this worked a treat, but I'm struggling to understand how to acheive the same thing with TypeScript.
Thanks