The listing can help you here:
enum YesNo { YES, NO } interface EnumObject { [enumValue: number]: string; } function getEnumValues(e: EnumObject): string[] { return Object.keys(e).map((i) => e[i]); } getEnumValues(YesNo);
type declaration does not create a character that can be used at run time, it only creates an alias in the type system. Therefore, you cannot use it as an argument to a function.
If you need to have string values ββfor the YesNo type, you can use the trick (since the string values ββof the enumerations are not part of TS yet ):
const YesNoEnum = { Yes: 'Yes', No: 'No' }; function thatAcceptsYesNoValue(vale: keyof typeof YesNoEnum): void {}
Then you can use getEnumValues(YesNoEnum) to get the possible values ββfor YesNoEnum , that is, ['Yes', 'No']. It's a little ugly, but it will work.
Honestly, I would only go with such a static variable:
type YesNo = 'yes' | 'no'; const YES_NO_VALUES: YesNo[] = ['yes', 'no'];
source share