Skip to content

Instantly share code, notes, and snippets.

@seanmhanson
Created September 27, 2022 19:43
Show Gist options
  • Save seanmhanson/b8bf84c2f7034b8d123eb7a1b3462f65 to your computer and use it in GitHub Desktop.
Save seanmhanson/b8bf84c2f7034b8d123eb7a1b3462f65 to your computer and use it in GitHub Desktop.
String Enums and Objects in TS
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