Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. export type EnumWithAssociatedValues<Params> = {
  2. [Key in keyof Params]: (values: Params[Key]) => Params[Key];
  3. };
  4.  
  5. export function associatedValue<T>() { return (null as unknown) as T; }
  6.  
  7. export function enumWithAssociatedValues<P>(params: P): EnumWithAssociatedValues<P> {
  8. const result: any = { };
  9. Object.keys(params).forEach((key: string) => {
  10. const Clazz = class { };
  11. result[key] = (args: any) => {
  12. const instance: any = new Clazz();
  13. Object.assign(instance, args);
  14. instance.key = key;
  15. return instance;
  16. };
  17. });
  18.  
  19. return result as EnumWithAssociatedValues<P>;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement