I'm struggling to find a solution for this seemingly simple issue. Let me break it down with a basic example:
const cookbook: CookBook = {
ingredients: {
"tomato": { vegetal: true },
"cheese": { vegetal: false },
"lettuce": { vegetal: true },
},
recipes: {
"pizza": ["tomato", "cheese"],
"salad": ["tomato", "lettuce"]
}
}
type CookBook = {
ingredients: {[key: string]: {vegetal: boolean}},
recipes: {[key: string]: string[]}
}
As shown in the recipes property, the values are lists of ingredient strings. But how can I ensure that these strings correspond to keys in the ingredients object?
...
recipes: {
// The inclusion of "pineapple" here should be prohibited
// as it is not a key in the ingredients property.
"pizza": ["tomato", "cheese", "pineapple"],
...
}
}