Created
April 29, 2019 07:23
-
-
Save rahmatrhd/d4fb76bce84ba0527dc9544f2ae6b389 to your computer and use it in GitHub Desktop.
How to make an object type with the keys are members of an enum
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
enum PrimaryColor { | |
Blue, | |
Red, | |
Yellow, | |
} | |
type ColorRecipe = { | |
[T in PrimaryColor]: number | |
} | |
const orangeRecipe: ColorRecipe = { | |
[PrimaryColor.Blue]: 0, | |
[PrimaryColor.Red]: 0.5, | |
[PrimaryColor.Yellow]: 0.5, | |
} | |
const greenRecipe: ColorRecipe = { | |
[PrimaryColor.Blue]: 0.5, | |
[PrimaryColor.Red]: 0, | |
[PrimaryColor.Yellow]: 0.5, | |
} | |
const purpleRecipe: ColorRecipe = { | |
[PrimaryColor.Blue]: 0.5, | |
[PrimaryColor.Red]: 0.5, | |
[PrimaryColor.Yellow]: 0, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment