|
| 1 | +import Vue from 'vue'; |
| 2 | +import { Dispatch, Commit } from 'vuex'; |
| 3 | +import { Wrapper } from 'vue-function-api'; |
| 4 | + |
| 5 | +type Dictionary<T> = { [key: string]: T }; |
| 6 | +type Computed = Wrapper<any>; |
| 7 | +type MutationMethod = (...args: any[]) => void; |
| 8 | +type ActionMethod = (...args: any[]) => Promise<any>; |
| 9 | +type CustomVue = Vue & Dictionary<any>; |
| 10 | + |
| 11 | +interface Mapper<R> { |
| 12 | + (map: string[]): Dictionary<R>; |
| 13 | + (map: Dictionary<string>): Dictionary<R>; |
| 14 | +} |
| 15 | + |
| 16 | +interface MapperWithNamespace<R> { |
| 17 | + (namespace: string, map: string[]): Dictionary<R>; |
| 18 | + (namespace: string, map: Dictionary<string>): Dictionary<R>; |
| 19 | +} |
| 20 | + |
| 21 | +interface FunctionMapper<F, R> { |
| 22 | + ( |
| 23 | + map: Dictionary<(this: CustomVue, fn: F, ...args: any[]) => any>, |
| 24 | + ): Dictionary<R>; |
| 25 | +} |
| 26 | + |
| 27 | +interface FunctionMapperWithNamespace<F, R> { |
| 28 | + ( |
| 29 | + namespace: string, |
| 30 | + map: Dictionary<(this: CustomVue, fn: F, ...args: any[]) => any>, |
| 31 | + ): Dictionary<R>; |
| 32 | +} |
| 33 | + |
| 34 | +interface MapperForState { |
| 35 | + <S>( |
| 36 | + map: Dictionary<(this: CustomVue, state: S, getters: any) => any>, |
| 37 | + ): Dictionary<Computed>; |
| 38 | +} |
| 39 | + |
| 40 | +interface MapperForStateWithNamespace { |
| 41 | + <S>( |
| 42 | + namespace: string, |
| 43 | + map: Dictionary<(this: CustomVue, state: S, getters: any) => any>, |
| 44 | + ): Dictionary<Computed>; |
| 45 | +} |
| 46 | + |
| 47 | +export type useState = Mapper<Computed> & |
| 48 | + MapperWithNamespace<Computed> & |
| 49 | + MapperForState & |
| 50 | + MapperForStateWithNamespace; |
| 51 | + |
| 52 | +export type useGetters = Mapper<Computed> & MapperWithNamespace<Computed>; |
| 53 | + |
| 54 | +export type useMutations = Mapper<MutationMethod> & |
| 55 | + MapperWithNamespace<MutationMethod> & |
| 56 | + FunctionMapper<Commit, MutationMethod> & |
| 57 | + FunctionMapperWithNamespace<Commit, MutationMethod>; |
| 58 | + |
| 59 | +export type useActions = Mapper<ActionMethod> & |
| 60 | + MapperWithNamespace<ActionMethod> & |
| 61 | + FunctionMapper<Dispatch, ActionMethod> & |
| 62 | + FunctionMapperWithNamespace<Dispatch, ActionMethod>; |
0 commit comments