export function actionTypesFactory( prefix: string, ...actionType: T ): { readonly [K in T[number]]: { default: K; begin: string; succeeded: string; failed: string; cancelled: string; }; }; export function actionTypesFactory( prefix: string, ...actionType: string[] ): { readonly [k: string]: { default: string; begin: string; succeeded: string; failed: string; cancelled: string; }; } { const prefixString = prefix.length ? `${prefix}/` : ""; return actionType.reduce( (acc, type) => ({ ...acc, [type]: { default: `${prefixString}${type}`, begin: `${prefixString}${type}_BEGIN`, succeeded: `${prefixString}${type}_SUCCEEDED`, failed: `${prefixString}${type}_FAILED`, cancelled: `${prefixString}${type}_CANCELLED`, }, }), {} ); } export function dictionaryFactory( ...args: T ): { readonly [K in T[number]]: K; }; export function dictionaryFactory( ...args: string[] ): { readonly [k: string]: string; } { return args.reduce( (prev, next) => ({ ...prev, [next]: next, }), {} ); }