I have created a custom dictionary class, but I am uncertain on how to define the Dictionary
attribute. There's a JSON file named Switches:
{"ShowImage": true,"ShowText": false, "showButton", true}
import * as switches from '../switches.json';
export class DictionaryClass{
Dictionary?: { [key: string]: boolean };
}
export function getDictionary() {
const dictionaryClass = new DictionaryClass();
dictionaryClass.Dictionary = { [key: string]: boolean };
for (let entry in switches) {
dictionaryClass.Dictionary[entry] = switches[entry];
}
return dictionaryClass;
}
In this scenario, I need guidance on properly instantiating the dictionary. Here is one unsuccessful attempt:
const dictionaryClass = new DictionaryClass();
dictionaryClass.Dictionary = { [key: string]: boolean };
I also tried the following approach, which also didn't work:
const dictionaryClass = new DictionaryClass();
dictionaryClass.Dictionary = switches;
Can someone advise me on the correct way to instantiate it? Additionally, instead of iterating through the JSON dictionary, is there a method to append the entire JSON dictionary to the dictionary
object?