Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export type EnumWithAssociatedValues<Params> = {
- [Key in keyof Params]: (values: Params[Key]) => Params[Key];
- };
- export function associatedValue<T>() { return (null as unknown) as T; }
- export function enumWithAssociatedValues<P>(params: P): EnumWithAssociatedValues<P> {
- const result: any = { };
- Object.keys(params).forEach((key: string) => {
- const Clazz = class { };
- result[key] = (args: any) => {
- const instance: any = new Clazz();
- Object.assign(instance, args);
- instance.key = key;
- return instance;
- };
- });
- return result as EnumWithAssociatedValues<P>;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement