Browse Source

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

fix #1736
Kia King Ishii 5 years ago
parent
commit
a934da95e4
2 changed files with 14 additions and 0 deletions
  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 createStore<S>(options: StoreOptions<S>): Store<S>;
 
 
+export function useStore<S = any>(): Store<S>;
+
 export interface Dispatch {
 export interface Dispatch {
   (type: string, payload?: any, options?: DispatchOptions): Promise<any>;
   (type: string, payload?: any, options?: DispatchOptions): Promise<any>;
   <P extends Payload>(payloadWithType: P, 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 });
   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 {
 namespace RootModule {
   const store = new Vuex.Store({
   const store = new Vuex.Store({
     state: {
     state: {