I do follow this idea to create an Enum(-like) structure in JavaScript with a Symbol:
const DATA = Object.freeze({
GOOD: Symbol("good"),
BAD: Symbol("bad"),
I_DONT_CARE: Symbol("i-dont-care"),
});
Now, I want to create a new object using the (unique) symbols to refer to each item and extend data about it:
const TRANSLATION = Object.freeze({
[DATA.GOOD]: "Gut",
[DATA.BAD]: "Schlecht",
[DATA.I_DONT_CARE]: "Egal",
});
This is indeed valid even though e.g. TypeScript did not believe that and complained, but this is being fixed too.
However, the problem now is that if I do Object.entries(TRANSLATION)
(or Object.keys(TRANSLATION)
/ Object.values(TRANSLATION)
) to further edit and convert that object, I do get an empty object.
It seems all Symbols
are ignored when iterating:
myenum = {
"bla": "blub",
[Symbol("test")]: "testData"
}
console.log(Object.keys(myenum));
I do not want that, I just want to use the symbols as unique keys, so I can store/"map" more information to a specific entry.