Skip to content

Commit

Permalink
fix(store): change types for overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
Brynze Maxim committed Mar 9, 2022
1 parent 2863091 commit 7bc63de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 3 additions & 6 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@ export declare class Store<S> {
subscribeAction<P extends ActionPayload>(fn: SubscribeActionOptions<P, S>, options?: SubscribeOptions): () => void;
watch<T>(getter: (state: S, getters: any) => T, cb: (value: T, oldValue: T) => void, options?: WatchOptions): () => void;

registerModule<T>(path: string, module: Module<T, S>, options?: ModuleOptions): void;
registerModule<T>(path: string[], module: Module<T, S>, options?: ModuleOptions): void;
registerModule<T>(path: string | string[], module: Module<T, S>, options?: ModuleOptions): void;

unregisterModule(path: string): void;
unregisterModule(path: string[]): void;
unregisterModule(path: string | string[]): void;

hasModule(path: string): boolean;
hasModule(path: string[]): boolean;
hasModule(path: string | string[]): boolean;

hotUpdate(options: {
actions?: ActionTree<S, S>;
Expand Down
10 changes: 10 additions & 0 deletions types/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ namespace RegisterModule {
};
}

function getInsideModulePath(): string | string[] {
return Math.random() > 0.5 ? ["c"] : "c"
}

const store = new Vuex.Store<RootState>({
state: {
value: 0
Expand All @@ -364,6 +368,12 @@ namespace RegisterModule {

store.hasModule(['a', 'b'])

store.registerModule(getInsideModulePath(), {
state: {value: 3}
})

store.hasModule(getInsideModulePath())

store.unregisterModule(["a", "b"]);
store.unregisterModule("a");
}
Expand Down

0 comments on commit 7bc63de

Please sign in to comment.