Say I have an array:
const fruits = ["Apple", "Orange", "Pear"];
and I want to define an object mapping each fruit to some fun facts about it:
interface Facts {
color: string,
typicalWeight: number
}
const fruitFacts: { [key: members of fruits]: Facts } = {
"Apple": { color: "green", typicalWeight: 150 }
//
}
How do I do that [key: members of fruits] part?
type FruitName = "Apple" | "Orange"; const fruitNames : FruitName[] = ["Apple", "Orange"];