Skip to content

Commit fd2b188

Browse files
alexjovermktsn
authored andcommitted
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
1 parent 71084f4 commit fd2b188

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

types/index.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export declare class Store<S> {
1717
dispatch: Dispatch;
1818
commit: Commit;
1919

20-
subscribe<P extends Payload>(fn: (mutation: P, state: S) => any): () => void;
20+
subscribe<P extends MutationPayload>(fn: (mutation: P, state: S) => any): () => void;
2121
watch<T>(getter: (state: S) => T, cb: (value: T, oldValue: T) => void, options?: WatchOptions): void;
2222

2323
registerModule<T>(path: string, module: Module<T, S>): void;
@@ -59,6 +59,10 @@ export interface Payload {
5959
type: string;
6060
}
6161

62+
export interface MutationPayload extends Payload {
63+
payload: any;
64+
}
65+
6266
export interface DispatchOptions {
6367
root?: boolean;
6468
}

types/test/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace StoreInstance {
3535

3636
store.subscribe((mutation, state) => {
3737
mutation.type;
38+
mutation.payload;
3839
state.value;
3940
});
4041

0 commit comments

Comments
 (0)