const myKey: string = 'something'
const myDict: { [id: string]: string } = {
myKey: 'some value',
}
and I would like the dictionary to look like:
{ 'something' : 'some value' }
but the actual result is:
{ myKey : 'some value' }
How can I force the constant to be replaced by its value when creating the dictionary?
You can do it the following way using ES6 computed property names:
const myKey = 'something';
const myDict = {[myKey]: 'some value'};
console.log(myDict);
More about computed property names can be found here - https://eloquentcode.com/computed-property-names-in-javascript