Skip to content

Instantly share code, notes, and snippets.

@sethdavis512
Created April 11, 2025 14:15
Show Gist options
  • Save sethdavis512/1d14ac456849e0f8c92056d0e48f1f2c to your computer and use it in GitHub Desktop.
Save sethdavis512/1d14ac456849e0f8c92056d0e48f1f2c to your computer and use it in GitHub Desktop.
// 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