From 7bc63ded99496f4c6e0d7a11b9b497dcd0865bb5 Mon Sep 17 00:00:00 2001 From: Brynze Maxim Date: Thu, 10 Mar 2022 01:28:09 +0300 Subject: [PATCH] fix(store): change types for overloads --- types/index.d.ts | 9 +++------ types/test/index.ts | 10 ++++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index aeb69617f..69ee03a9a 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -24,14 +24,11 @@ export declare class Store { subscribeAction

(fn: SubscribeActionOptions, options?: SubscribeOptions): () => void; watch(getter: (state: S, getters: any) => T, cb: (value: T, oldValue: T) => void, options?: WatchOptions): () => void; - registerModule(path: string, module: Module, options?: ModuleOptions): void; - registerModule(path: string[], module: Module, options?: ModuleOptions): void; + registerModule(path: string | string[], module: Module, 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; diff --git a/types/test/index.ts b/types/test/index.ts index 32d5ec2c6..a03bdff11 100644 --- a/types/test/index.ts +++ b/types/test/index.ts @@ -342,6 +342,10 @@ namespace RegisterModule { }; } + function getInsideModulePath(): string | string[] { + return Math.random() > 0.5 ? ["c"] : "c" + } + const store = new Vuex.Store({ state: { value: 0 @@ -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"); }