Skip to content

Commit a934da9

Browse files
authored
types: add useStore function (#1736) (#1739)
fix #1736
1 parent f18d5d4 commit a934da9

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

types/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export declare class Store<S> {
4343

4444
export function createStore<S>(options: StoreOptions<S>): Store<S>;
4545

46+
export function useStore<S = any>(): Store<S>;
47+
4648
export interface Dispatch {
4749
(type: string, payload?: any, options?: DispatchOptions): Promise<any>;
4850
<P extends Payload>(payloadWithType: P, options?: DispatchOptions): Promise<any>;

types/test/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ namespace StoreInstance {
7878
store.replaceState({ value: 10 });
7979
}
8080

81+
namespace UseStoreFunction {
82+
interface State {
83+
a: string
84+
}
85+
86+
const storeWithState = Vuex.useStore<State>()
87+
storeWithState.state.a
88+
89+
const storeAsAny = Vuex.useStore()
90+
storeAsAny.state.a
91+
}
92+
8193
namespace RootModule {
8294
const store = new Vuex.Store({
8395
state: {

0 commit comments

Comments
 (0)