Prechádzať zdrojové kódy

fix(types): add lost argument of useStore (#1803)

Eduard Aksamitov 4 rokov pred
rodič
commit
657afe3db4
2 zmenil súbory, kde vykonal 11 pridanie a 2 odobranie
  1. 2 2
      types/index.d.ts
  2. 9 0
      types/test/index.ts

+ 2 - 2
types/index.d.ts

@@ -15,7 +15,7 @@ export declare class Store<S> {
   readonly state: S;
   readonly state: S;
   readonly getters: any;
   readonly getters: any;
 
 
-  install(app: App, injectKey?: InjectionKey<Store<any>>): void;
+  install(app: App, injectKey?: InjectionKey<Store<any>> | string): void;
 
 
   replaceState(state: S): void;
   replaceState(state: S): void;
 
 
@@ -45,7 +45,7 @@ export declare class Store<S> {
 
 
 export function createStore<S>(options: StoreOptions<S>): Store<S>;
 export function createStore<S>(options: StoreOptions<S>): Store<S>;
 
 
-export function useStore<S = any>(): Store<S>;
+export function useStore<S = any>(injectKey?: InjectionKey<Store<S>> | string): Store<S>;
 
 
 export interface Dispatch {
 export interface Dispatch {
   (type: string, payload?: any, options?: DispatchOptions): Promise<any>;
   (type: string, payload?: any, options?: DispatchOptions): Promise<any>;

+ 9 - 0
types/test/index.ts

@@ -1,3 +1,4 @@
+import { InjectionKey } from "vue";
 import * as Vuex from "../index";
 import * as Vuex from "../index";
 
 
 namespace StoreInstance {
 namespace StoreInstance {
@@ -138,6 +139,14 @@ namespace UseStoreFunction {
     a: string
     a: string
   }
   }
 
 
+  const key: InjectionKey<string> = Symbol('store')
+
+  const storeWithKey = Vuex.useStore(key)
+  storeWithKey.state.a
+
+  const storeWithKeyString = Vuex.useStore('store')
+  storeWithKeyString.state.a
+
   const storeWithState = Vuex.useStore<State>()
   const storeWithState = Vuex.useStore<State>()
   storeWithState.state.a
   storeWithState.state.a