As an illustration
enum Size {
Small: 'smallSize'
Medium: 'mediumSize'
Large: 'largeSize'
}
enum Weekday {
Monday: 'Monday'
Tuesday: 'Tuesday'
...
}
// Need only Size.Medium and Size.Large, as well as from 1 to 7 entries for Weekdays
const mapping: { [size in Size]?: { [weekday in Weekday]? : MenuType } = {
[Size.Medium] : { Weekday.Tuesday : <menuObject> }
[Size.Large] : {
Weekday.Monday : <menuObject>
Weekday.Friday : <menuObject>
}
}
Upon attempting to retrieve the menu using
const menu = mapping[Size.Large][Weekday.Monday]
, an error occurs indicating that Object is possibly undefined
.
What would be the most effective approach to establish this mapping while preserving strong typing?