Created
September 27, 2022 19:43
-
-
Save seanmhanson/b8bf84c2f7034b8d123eb7a1b3462f65 to your computer and use it in GitHub Desktop.
String Enums and Objects in TS
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 Muses { | |
CALLIOPE = 'calliope', | |
CLIO = 'clio', | |
EUTERPE = 'euterpe', | |
THALIA = 'thalia', | |
MELPOMENE = 'melpomene', | |
TERPSICHORE = 'terpsichore', | |
ERATO = 'erato', | |
POLYHYMNIA = 'polyhymnia', | |
URANIA = 'urania', | |
} | |
type MuseNames = keyof typeof Muses; | |
// MuseNames = "CALLIOPE" | "CLIO" | "EUTERPE" | "THALIA" | "MELPOMENE" | "TERPSICHORE" | "ERATO" | "POLYHYMNIA" | "URANIA" | |
type MuseReference = { | |
[key in Muses]: string; | |
} | |
/** | |
* type MuseReference = { | |
calliope: string; | |
clio: string; | |
euterpe: string; | |
thalia: string; | |
melpomene: string; | |
terpsichore: string; | |
erato: string; | |
polyhymnia: string; | |
urania: string; | |
} | |
*/ | |
const muses: MuseReference = { | |
[Muses.CALLIOPE]: 'epic poetry', | |
[Muses.CLIO]: 'history', | |
[Muses.EUTERPE]: 'music', | |
[Muses.THALIA]: 'comedic poetry', | |
[Muses.MELPOMENE]: 'tragedy', | |
[Muses.TERPSICHORE]: 'dance', | |
[Muses.ERATO]: 'lyric poetry', | |
[Muses.POLYHYMNIA]: 'sacred poetry', | |
[Muses.URANIA]: 'astronomy', | |
} as const; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment