Created
April 11, 2025 14:15
-
-
Save sethdavis512/1d14ac456849e0f8c92056d0e48f1f2c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define an enum with some color keys and their corresponding values | |
enum Colors { | |
Red = "#FF0000", | |
Green = "#00FF00", | |
Blue = "#0000FF", | |
} | |
// Function to get the value of a color by its key | |
function getColorValue(colorKey: keyof typeof Colors): string { | |
return Colors[colorKey]; | |
} | |
// Example usage | |
const selectedColorKey: keyof typeof Colors = "Red"; | |
const selectedColorValue = getColorValue(selectedColorKey); | |
console.log(`The value of ${selectedColorKey} is ${selectedColorValue}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment