Skip to content

Instantly share code, notes, and snippets.

@alxhub
Created March 6, 2018 20:51
Show Gist options
  • Save alxhub/6526b5a843f1a241a1e6e9f568d45659 to your computer and use it in GitHub Desktop.
Save alxhub/6526b5a843f1a241a1e6e9f568d45659 to your computer and use it in GitHub Desktop.
function extendEnum(classType: any, enumType: any): void {
for (let key in enumType) {
classType[key] = enumType[key];
}
}
enum EnumType {
OPTION_A,
OPTION_B,
}
class ClassType {
static operation(): void {
console.log('Do some operation');
}
}
extendEnum(ClassType, EnumType);
type Result = EnumType;
const Result: (typeof ClassType)&(typeof EnumType) = ClassType as any;
function useResult(result: Result) {
console.log(Result[result]);
}
Result.operation();
useResult(Result.OPTION_A);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment