Last active
April 12, 2022 19:02
-
-
Save NewEXE/a12d13a15395ee318cef27b401985a7b to your computer and use it in GitHub Desktop.
Typescript Enum to Array
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
/** For key/value enum: */ | |
export enum CountryEnum { | |
fra = 'FRANCE', | |
ukr = 'UKRAINE', | |
} | |
// ['FRANCE', 'UKRAINE'] | |
export const CountryList = Object.entries(CountryEnum).map( | |
([, value]) => value, | |
); | |
// ['fra', 'ukr'] | |
export const CountryKeysList = Object.entries(CountryEnum).map(([key]) => key); | |
/** For values-only enum: */ | |
export enum ExtensionsEnum { | |
'ext1', | |
'ext2', | |
} | |
// ['ext1', 'ext2'] | |
export const ExtensionsEnum = Object.values( | |
EnterpriseExtensionsEnum, | |
).filter((value) => typeof value !== 'number'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment