helpers.d.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import Vue from 'vue';
  2. import { Dispatch, Commit } from './index';
  3. type Dictionary<T> = { [key: string]: T };
  4. type Computed = () => any;
  5. type MutationMethod = (...args: any[]) => void;
  6. type ActionMethod = (...args: any[]) => Promise<any>;
  7. type CustomVue = Vue & Dictionary<any>;
  8. interface Mapper<R> {
  9. (map: string[]): Dictionary<R>;
  10. (map: Dictionary<string>): Dictionary<R>;
  11. }
  12. interface MapperWithNamespace<R> {
  13. (namespace: string, map: string[]): Dictionary<R>;
  14. (namespace: string, map: Dictionary<string>): Dictionary<R>;
  15. }
  16. interface FunctionMapper<F, R> {
  17. (map: Dictionary<(this: CustomVue, fn: F, ...args: any[]) => any>): Dictionary<R>;
  18. }
  19. interface FunctionMapperWithNamespace<F, R> {
  20. (
  21. namespace: string,
  22. map: Dictionary<(this: CustomVue, fn: F, ...args: any[]) => any>
  23. ): Dictionary<R>;
  24. }
  25. interface MapperForState {
  26. <S>(
  27. map: Dictionary<(this: CustomVue, state: S, getters: any) => any>
  28. ): Dictionary<Computed>;
  29. }
  30. interface MapperForStateWithNamespace {
  31. <S>(
  32. namespace: string,
  33. map: Dictionary<(this: CustomVue, state: S, getters: any) => any>
  34. ): Dictionary<Computed>;
  35. }
  36. interface NamespacedMappers {
  37. mapState: Mapper<Computed> & MapperForState;
  38. mapMutations: Mapper<MutationMethod> & FunctionMapper<Commit, MutationMethod>;
  39. mapGetters: Mapper<Computed>;
  40. mapActions: Mapper<ActionMethod> & FunctionMapper<Dispatch, ActionMethod>;
  41. }
  42. export declare const mapState: Mapper<Computed>
  43. & MapperWithNamespace<Computed>
  44. & MapperForState
  45. & MapperForStateWithNamespace;
  46. export declare const mapMutations: Mapper<MutationMethod>
  47. & MapperWithNamespace<MutationMethod>
  48. & FunctionMapper<Commit, MutationMethod>
  49. & FunctionMapperWithNamespace<Commit, MutationMethod>;
  50. export declare const mapGetters: Mapper<Computed>
  51. & MapperWithNamespace<Computed>;
  52. export declare const mapActions: Mapper<ActionMethod>
  53. & MapperWithNamespace<ActionMethod>
  54. & FunctionMapper<Dispatch, ActionMethod>
  55. & FunctionMapperWithNamespace<Dispatch, ActionMethod>;
  56. export declare function createNamespacedHelpers(namespace: string): NamespacedMappers;