Przeglądaj źródła

types: add `useStore` function (#1736) (#1739)

fix #1736
Kia King Ishii 5 lat temu
rodzic
commit
a934da95e4
2 zmienionych plików z 14 dodań i 0 usunięć
  1. 2 0
      types/index.d.ts
  2. 12 0
      types/test/index.ts

+ 2 - 0
types/index.d.ts

@@ -43,6 +43,8 @@ export declare class Store<S> {
 
 export function createStore<S>(options: StoreOptions<S>): Store<S>;
 
+export function useStore<S = any>(): Store<S>;
+
 export interface Dispatch {
   (type: string, payload?: any, options?: DispatchOptions): Promise<any>;
   <P extends Payload>(payloadWithType: P, options?: DispatchOptions): Promise<any>;

+ 12 - 0
types/test/index.ts

@@ -78,6 +78,18 @@ namespace StoreInstance {
   store.replaceState({ value: 10 });
 }
 
+namespace UseStoreFunction {
+  interface State {
+    a: string
+  }
+
+  const storeWithState = Vuex.useStore<State>()
+  storeWithState.state.a
+
+  const storeAsAny = Vuex.useStore()
+  storeAsAny.state.a
+}
+
 namespace RootModule {
   const store = new Vuex.Store({
     state: {