Skip to content

Instantly share code, notes, and snippets.

@TylerSustare
Created June 12, 2020 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TylerSustare/83e6ba1a94ceff52cc7ad43047dc82f5 to your computer and use it in GitHub Desktop.
Save TylerSustare/83e6ba1a94ceff52cc7ad43047dc82f5 to your computer and use it in GitHub Desktop.
Itterate through string enum in TypeScript
export enum EnumType {
choice = 'choice',
checkbox = 'checkbox',
boolean = 'boolean',
blank = 'blank',
match = 'match',
order = 'order'
}
export const getEnumTypeValues = (): { key: string; text: string }[] =>
Object.keys(EnumType).map((type) => {
switch (type) {
case 'choice':
return { key: type, text: 'Multiple Choice (one correct answer)' };
case 'checkbox':
return { key: type, text: 'Select Multiple (multiple correct answers)' };
case 'boolean':
return { key: type, text: 'True or False' };
case 'blank':
return { key: type, text: 'Fill in the Blank' };
case 'match':
return { key: type, text: 'Matching' };
case 'order':
return { key: type, text: 'Ordered Answer' };
default:
throw new Error('Unknown Enum Type');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment