An object named CONFIG holds the following information:
export const CONFIG = {
buttonDestinations: {
detailedStats: `detailedStats`,
mealPlans: `mealPlans`,
products: `products`
},
buttonTexts: {
detailedStats: `detailed stats`,
mealPlans: `meal plans`,
products: `products`
},
buttonConfigTypes: {
detailedStats: `detailedStats`,
mealPlans: `mealPlans`,
products: `products`
},
navigationVisibilityThreshold: 100
}
This object is later referenced like this:
let configType
switch (true) {
case elementsVisibility.detailedStats:
configType = CONFIG.buttonConfigTypes.detailedStats
break
case elementsVisibility.selectedMealPlan:
configType = CONFIG.buttonConfigTypes.mealPlans
break
case this.isSelectedProduct:
configType = CONFIG.buttonConfigTypes.products
...
}
if (configType) {
button.destination = CONFIG[configType].destination
button.text = CONFIG[configType].text
}
...
However, TypeScript gives a warning:
TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ buttonDestinations: { detailedStats: string; mealPlans: string; products: string; }; buttonTexts: { detailedStats: string; mealPlans: string; products: string; }; buttonConfigTypes: { detailedStats: string; mealPlans: string; products: string; }; navigationVisibilityThreshold: number; }'. No index signature with a parameter of type 'string' was found on type '{ buttonDestinations: { detailedStats: string; mealPlans: string; products: string; }; buttonTexts: { detailedStats: string; mealPlans: string; products: string; }; buttonConfigTypes: { detailedStats: string; mealPlans: string; products: string; }; navigationVisibilityThreshold: number; }'.
Any suggestions on how to allow keys of the same object to index it?