helpers.d.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. interface Mapper<R> {
  8. (map: string[]): Dictionary<R>;
  9. (map: Dictionary<string>): Dictionary<R>;
  10. }
  11. interface MapperWithNamespace<R> {
  12. (namespace: string, map: string[]): Dictionary<R>;
  13. (namespace: string, map: Dictionary<string>): Dictionary<R>;
  14. }
  15. interface FunctionMapper<F, R> {
  16. (map: Dictionary<(this: typeof Vue, fn: F, ...args: any[]) => any>): Dictionary<R>;
  17. }
  18. interface FunctionMapperWithNamespace<F, R> {
  19. (
  20. namespace: string,
  21. map: Dictionary<(this: typeof Vue, fn: F, ...args: any[]) => any>
  22. ): Dictionary<R>;
  23. }
  24. interface MapperForState {
  25. <S>(
  26. map: Dictionary<(this: typeof Vue, state: S, getters: any) => any>
  27. ): Dictionary<Computed>;
  28. }
  29. interface MapperForStateWithNamespace {
  30. <S>(
  31. namespace: string,
  32. map: Dictionary<(this: typeof Vue, state: S, getters: any) => any>
  33. ): Dictionary<Computed>;
  34. }
  35. interface NamespacedMappers {
  36. mapState: Mapper<Computed> & MapperForState;
  37. mapMutations: Mapper<MutationMethod> & FunctionMapper<Commit, MutationMethod>;
  38. mapGetters: Mapper<Computed>;
  39. mapActions: Mapper<ActionMethod> & FunctionMapper<Dispatch, ActionMethod>;
  40. }
  41. export declare const mapState: Mapper<Computed>
  42. & MapperWithNamespace<Computed>
  43. & MapperForState
  44. & MapperForStateWithNamespace;
  45. export declare const mapMutations: Mapper<MutationMethod>
  46. & MapperWithNamespace<MutationMethod>
  47. & FunctionMapper<Commit, MutationMethod>
  48. & FunctionMapperWithNamespace<Commit, MutationMethod>;
  49. export declare const mapGetters: Mapper<Computed>
  50. & MapperWithNamespace<Computed>;
  51. export declare const mapActions: Mapper<ActionMethod>
  52. & MapperWithNamespace<ActionMethod>
  53. & FunctionMapper<Dispatch, ActionMethod>
  54. & FunctionMapperWithNamespace<Dispatch, ActionMethod>;
  55. export declare function createNamespacedHelpers(namespace: string): NamespacedMappers;