Repository navigation
Enum Problem #51150
Copy link
Copy link
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
Bug Report
🔎 Search Terms
🕗 Version & Regression Information
- This is a crash
- This changed between versions ______ and _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______
⏯ Playground Link
Playground link with relevant code
💻 Code
// We can quickly address your report if:
// - The code sample is short. Nearly all TypeScript bugs can be demonstrated in 20-30 lines of code!
// - It doesn't use external libraries. These are often issues with the type definitions rather than TypeScript bugs.
// - The incorrectness of the behavior is readily apparent from reading the sample.
// Reports are slower to investigate if:
// - We have to pare too much extraneous code.
// - We have to clone a large repo and validate that the problem isn't elsewhere.
// - The sample is confusing or doesn't clearly demonstrate what's wrong.🙁 Actual behavior
When you iterate through enum keys you find that the keys are logged then the values of each key are logged as well when using Object.keys(). When you use Object.entries() you find that the keys and values on the original object are printed and then the values are printed as the keys and the keys printed as values. This all happens during the same iteration.
🙂 Expected behavior
I expected the keys and values to be logged when using Object.entries() . When I use Object.keys() i expect the keys to be logged not the values at all
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug

Activity
fatcerberus commentedon Oct 12, 2022
Working as intended. Number-valued enums contain bidirectional mappings so that, e.g.
Foo[Foo.Bad]is"Bad". This is so you can more easily look up enum values in the debugger. If you don't want the reverse mappings you could try a string-valued enum.MartinJohns commentedon Oct 12, 2022
This is working as intended. Enums in TypeScript are reverse mapped. You can see this by looking at the generated JavaScript: