index.d.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. }
  39. interface ModuleTree {
  40. [key: string]: Module<any>;
  41. }
  42. interface ComponentOption<S> {
  43. getters: { [key: string]: Getter<S, any> };
  44. actions: { [key: string]: Action<S> };
  45. }
  46. interface WatchOption {
  47. deep?: boolean;
  48. immidiate?: boolean;
  49. }
  50. function createLogger<S>(option: LoggerOption<S>): Plugin<S>;
  51. interface LoggerOption<S> {
  52. collapsed?: boolean;
  53. transformer?: (state: S) => any;
  54. mutationTransformer?: (mutation: MutationObject<any>) => any;
  55. }
  56. }
  57. declare namespace vuejs {
  58. interface ComponentOption {
  59. vuex?: Vuex.ComponentOption<any>;
  60. store?: Vuex.Store<any>;
  61. }
  62. interface Vue {
  63. $store?: Vuex.Store<any>;
  64. }
  65. }
  66. declare module 'vuex' {
  67. export = Vuex
  68. }
  69. declare module 'vuex/logger' {
  70. export default Vuex.createLogger;
  71. }