index.d.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. on(event: string, cb: (...args: any[]) => void): void;
  14. once(event: string, cb: (...args: any[]) => void): void;
  15. off(event?: string, cb?: (...args: any[]) => void): void;
  16. emit(event: string, ...args: any[]): void;
  17. }
  18. function install(Vue: vuejs.VueStatic): void;
  19. interface StoreOption<S> {
  20. state?: S;
  21. mutations?: MutationTree<S>;
  22. modules?: ModuleTree;
  23. plugins?: Plugin<S>[];
  24. strict?: boolean;
  25. }
  26. type Getter<S, T> = (state: S) => T;
  27. type Action<S> = (store: Store<S>, ...args: any[]) => any;
  28. type Mutation<S> = (state: S, ...args: any[]) => void;
  29. type Plugin<S> = (store: Store<S>) => void;
  30. interface MutationTree<S> {
  31. [key: string]: Mutation<S>;
  32. }
  33. interface MutationObject<P> {
  34. type: string;
  35. silent?: boolean;
  36. payload?: P;
  37. }
  38. interface Module<S> {
  39. state: S;
  40. mutations: MutationTree<S>;
  41. }
  42. interface ModuleTree {
  43. [key: string]: Module<any>;
  44. }
  45. interface ComponentOption<S> {
  46. getters: { [key: string]: Getter<S, any> };
  47. actions: { [key: string]: Action<S> };
  48. }
  49. interface WatchOption {
  50. deep?: boolean;
  51. immidiate?: boolean;
  52. }
  53. function createLogger<S>(option: LoggerOption<S>): Plugin<S>;
  54. interface LoggerOption<S> {
  55. collapsed?: boolean;
  56. transformer?: (state: S) => any;
  57. mutationTransformer?: (mutation: MutationObject<any>) => any;
  58. }
  59. }
  60. declare namespace vuejs {
  61. interface ComponentOption {
  62. vuex?: Vuex.ComponentOption<any>;
  63. store?: Vuex.Store<any>;
  64. }
  65. interface Vue {
  66. $store?: Vuex.Store<any>;
  67. }
  68. }
  69. declare module 'vuex' {
  70. export = Vuex
  71. }
  72. declare module 'vuex/logger' {
  73. export default Vuex.createLogger;
  74. }