Created
June 12, 2020 18:48
-
-
Save TylerSustare/83e6ba1a94ceff52cc7ad43047dc82f5 to your computer and use it in GitHub Desktop.
Itterate through string enum in TypeScript
This file contains hidden or 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
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