Created
March 6, 2018 20:51
-
-
Save alxhub/6526b5a843f1a241a1e6e9f568d45659 to your computer and use it in GitHub Desktop.
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
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