Avatar ·

How to get names (keys) of enum values in TypeScript?

Hello! I'm new to TypeScript and encountered a problem when working with enums. Let's say I have this enum: ```typescript enum Color { Red = 1, Green = 2, Blue = 4 } ``` I want to dynamically get a list of all names (keys) of this enum, i.e., an array of strings: `["Red", "Green", "Blue"]`. I tried using `Object.keys(Color)`, but I'm not getting what I expect. In the console, numbers also appear: `["1", "2", "4", "Red", "Green", "Blue"]`. Why is this happening? Is this a TypeScript bug? I specifically need to get the names, for example, to display them in a dropdown list on the UI or for validating user input. How can I do this correctly? Is there a built-in function or do I need to write my own? I would be grateful for a detailed explanation with examples.