Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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