index.d.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. declare namespace Vuex {
  2. class Store<S> {
  3. constructor(options: StoreOption<S>);
  4. state: S;
  5. dispatch(mutationName: string, ...args: any[]): void;
  6. dispatch<P>(mutation: MutationObject<P>): void;
  7. replaceState(state: S): void;
  8. watch<T>(getter: Getter<S, T>, cb: (value: T) => void, options?: WatchOption): void;
  9. hotUpdate(options: {
  10. mutations?: MutationTree<S>;
  11. modules?: ModuleTree;
  12. }): void;
  13. subscribe(cb: (mutation: MutationObject<any>, state: S) => void): () => void;
  14. }
  15. function install(Vue: vuejs.VueStatic): void;
  16. interface StoreOption<S> {
  17. state?: S;
  18. mutations?: MutationTree<S>;
  19. modules?: ModuleTree;
  20. plugins?: Plugin<S>[];
  21. strict?: boolean;
  22. }
  23. type Getter<S, T> = (state: S) => T;
  24. type Action<S> = (store: Store<S>, ...args: any[]) => any;
  25. type Mutation<S> = (state: S, ...args: any[]) => void;
  26. type Plugin<S> = (store: Store<S>) => void;
  27. interface MutationTree<S> {
  28. [key: string]: Mutation<S>;
  29. }
  30. interface MutationObject<P> {
  31. type: string;
  32. silent?: boolean;
  33. payload?: P;
  34. }
  35. interface Module<S> {
  36. state?: S;
  37. mutations?: MutationTree<S>;
  38. modules?: ModuleTree;
  39. }
  40. interface ModuleTree {
  41. [key: string]: Module<any>;
  42. }
  43. interface ComponentOption<S> {
  44. getters: { [key: string]: Getter<S, any> };
  45. actions: { [key: string]: Action<S> };
  46. }
  47. interface WatchOption {
  48. deep?: boolean;
  49. immidiate?: boolean;
  50. }
  51. function createLogger<S>(option: LoggerOption<S>): Plugin<S>;
  52. interface LoggerOption<S> {
  53. collapsed?: boolean;
  54. transformer?: (state: S) => any;
  55. mutationTransformer?: (mutation: MutationObject<any>) => any;
  56. }
  57. }
  58. declare namespace vuejs {
  59. interface ComponentOption {
  60. vuex?: Vuex.ComponentOption<any>;
  61. store?: Vuex.Store<any>;
  62. }
  63. interface Vue {
  64. $store?: Vuex.Store<any>;
  65. }
  66. }
  67. declare module 'vuex' {
  68. export = Vuex
  69. }
  70. declare module 'vuex/logger' {
  71. export default Vuex.createLogger;
  72. }