|
1 | 1 | import Vue = require("vue"); |
2 | 2 |
|
3 | 3 | type Dictionary<T> = { [key: string]: T }; |
| 4 | +type Computed = () => any; |
| 5 | +type MutationMethod = (...args: any[]) => void; |
| 6 | +type ActionMethod = (...args: any[]) => Promise<any>; |
4 | 7 |
|
5 | | -export function mapState (map: string[]): Dictionary<() => any>; |
6 | | -export function mapState (namespace: string, map: string[]): Dictionary<() => any>; |
7 | | -export function mapState (map: Dictionary<string>): Dictionary<() => any>; |
8 | | -export function mapState (namespace: string, map: Dictionary<string>): Dictionary<() => any>; |
9 | | -export function mapState <S>( |
10 | | - map: Dictionary<(this: typeof Vue, state: S, getters: any) => any> |
11 | | -): Dictionary<() => any>; |
12 | | -export function mapState <S>( |
13 | | - namespace: string, |
14 | | - map: Dictionary<(this: typeof Vue, state: S, getters: any) => any> |
15 | | -): Dictionary<() => any>; |
| 8 | +interface Mapper<R> { |
| 9 | + (map: string[]): Dictionary<R>; |
| 10 | + (map: Dictionary<string>): Dictionary<R>; |
| 11 | +} |
16 | 12 |
|
17 | | -type MutationMethod = (...args: any[]) => void; |
18 | | -export function mapMutations (map: string[]): Dictionary<MutationMethod>; |
19 | | -export function mapMutations (namespace: string, map: string[]): Dictionary<MutationMethod>; |
20 | | -export function mapMutations (map: Dictionary<string>): Dictionary<MutationMethod>; |
21 | | -export function mapMutations (namespace: string, map: Dictionary<string>): Dictionary<MutationMethod>; |
22 | | - |
23 | | -export function mapGetters (map: string[]): Dictionary<() => any>; |
24 | | -export function mapGetters (namespace: string, map: string[]): Dictionary<() => any>; |
25 | | -export function mapGetters (map: Dictionary<string>): Dictionary<() => any>; |
26 | | -export function mapGetters (namespace: string, map: Dictionary<string>): Dictionary<() => any>; |
27 | | - |
28 | | -type ActionMethod = (...args: any[]) => Promise<any[]>; |
29 | | -export function mapActions (map: string[]): Dictionary<ActionMethod>; |
30 | | -export function mapActions (namespace: string, map: string[]): Dictionary<ActionMethod>; |
31 | | -export function mapActions (map: Dictionary<string>): Dictionary<ActionMethod>; |
32 | | -export function mapActions (namespace: string, map: Dictionary<string>): Dictionary<ActionMethod>; |
| 13 | +interface MapperWithNamespace<R> { |
| 14 | + (namespace: string, map: string[]): Dictionary<R>; |
| 15 | + (namespace: string, map: Dictionary<string>): Dictionary<R>; |
| 16 | +} |
| 17 | + |
| 18 | +interface MapperForState { |
| 19 | + <S>( |
| 20 | + map: Dictionary<(this: typeof Vue, state: S, getters: any) => any> |
| 21 | + ): Dictionary<Computed>; |
| 22 | +} |
| 23 | + |
| 24 | +interface MapperForStateWithNamespace { |
| 25 | + <S>( |
| 26 | + namespace: string, |
| 27 | + map: Dictionary<(this: typeof Vue, state: S, getters: any) => any> |
| 28 | + ): Dictionary<Computed>; |
| 29 | +} |
| 30 | + |
| 31 | +interface NamespacedMappers { |
| 32 | + mapState: Mapper<Computed> & MapperForState; |
| 33 | + mapMutations: Mapper<MutationMethod>; |
| 34 | + mapGetters: Mapper<Computed>; |
| 35 | + mapActions: Mapper<ActionMethod>; |
| 36 | +} |
| 37 | + |
| 38 | +export declare const mapState: Mapper<Computed> |
| 39 | + & MapperWithNamespace<Computed> |
| 40 | + & MapperForState |
| 41 | + & MapperForStateWithNamespace; |
| 42 | + |
| 43 | +export declare const mapMutations: Mapper<MutationMethod> |
| 44 | + & MapperWithNamespace<MutationMethod>; |
| 45 | + |
| 46 | +export declare const mapGetters: Mapper<Computed> |
| 47 | + & MapperWithNamespace<Computed>; |
| 48 | + |
| 49 | +export declare const mapActions: Mapper<ActionMethod> |
| 50 | + & MapperWithNamespace<ActionMethod>; |
| 51 | + |
| 52 | +export declare function createNamespacedHelpers(namespace: string): NamespacedMappers; |
0 commit comments