Explorar o código

Add MutationPayload type (#869)

* Add MutationPayload type

On the subscribe function, the mutation object was only having the `type` property and missing the payload

* Add tests for MutationPayload
Alex Jover %!s(int64=7) %!d(string=hai) anos
pai
achega
fd2b188fe5
Modificáronse 2 ficheiros con 6 adicións e 1 borrados
  1. 5 1
      types/index.d.ts
  2. 1 0
      types/test/index.ts

+ 5 - 1
types/index.d.ts

@@ -17,7 +17,7 @@ export declare class Store<S> {
   dispatch: Dispatch;
   commit: Commit;
 
-  subscribe<P extends Payload>(fn: (mutation: P, state: S) => any): () => void;
+  subscribe<P extends MutationPayload>(fn: (mutation: P, state: S) => any): () => void;
   watch<T>(getter: (state: S) => T, cb: (value: T, oldValue: T) => void, options?: WatchOptions): void;
 
   registerModule<T>(path: string, module: Module<T, S>): void;
@@ -59,6 +59,10 @@ export interface Payload {
   type: string;
 }
 
+export interface MutationPayload extends Payload {
+  payload: any;
+}
+
 export interface DispatchOptions {
   root?: boolean;
 }

+ 1 - 0
types/test/index.ts

@@ -35,6 +35,7 @@ namespace StoreInstance {
 
   store.subscribe((mutation, state) => {
     mutation.type;
+    mutation.payload;
     state.value;
   });