|
1 | 1 | import Vue from 'vue'; |
2 | 2 | import { Dispatch, Commit } from './index'; |
3 | 3 |
|
4 | | -type Dictionary<T> = { [key: string]: T }; |
| 4 | +type CompleteObject = { [key: string]: string }; |
5 | 5 | type Computed = () => any; |
6 | 6 | type MutationMethod = (...args: any[]) => void; |
7 | 7 | type ActionMethod = (...args: any[]) => Promise<any>; |
8 | 8 |
|
9 | 9 | interface Mapper<R> { |
10 | | - (map: string[]): Dictionary<R>; |
11 | | - (map: Dictionary<string>): Dictionary<R>; |
| 10 | + <T extends CompleteObject, K extends keyof T>(map: K[]): { [key in K]: R }; |
| 11 | + <T extends CompleteObject, K extends keyof T>(map: { [key in K]: string }): { [key in K]: R }; |
12 | 12 | } |
13 | 13 |
|
14 | 14 | interface MapperWithNamespace<R> { |
15 | | - (namespace: string, map: string[]): Dictionary<R>; |
16 | | - (namespace: string, map: Dictionary<string>): Dictionary<R>; |
| 15 | + <T extends CompleteObject, K extends keyof T>(namespace: string, map: K[]): { [key in K]: R }; |
| 16 | + <T extends CompleteObject, K extends keyof T>(namespace: string, map: { [key in K]: string }): { [key in K]: R }; |
17 | 17 | } |
18 | 18 |
|
| 19 | +type MappingFunction<F> = (this: typeof Vue, fn: F, ...args: any[]) => any |
| 20 | + |
19 | 21 | interface FunctionMapper<F, R> { |
20 | | - (map: Dictionary<(this: typeof Vue, fn: F, ...args: any[]) => any>): Dictionary<R>; |
| 22 | + <T extends CompleteObject, K extends keyof T>(map: { [key in K]: MappingFunction<F> }): { [key in K]: R }; |
21 | 23 | } |
22 | 24 |
|
23 | 25 | interface FunctionMapperWithNamespace<F, R> { |
24 | | - ( |
| 26 | + <T extends CompleteObject, K extends keyof T>( |
25 | 27 | namespace: string, |
26 | | - map: Dictionary<(this: typeof Vue, fn: F, ...args: any[]) => any> |
27 | | - ): Dictionary<R>; |
| 28 | + map: { [key in K]: MappingFunction<F> } |
| 29 | + ): { [key in K]: R }; |
28 | 30 | } |
29 | 31 |
|
| 32 | +type StateMappingFunction<S> = (this: typeof Vue, state: S, getters: any) => any |
| 33 | + |
30 | 34 | interface MapperForState { |
31 | | - <S>( |
32 | | - map: Dictionary<(this: typeof Vue, state: S, getters: any) => any> |
33 | | - ): Dictionary<Computed>; |
| 35 | + <S, T extends CompleteObject, K extends keyof T>( |
| 36 | + map: { [key in K]: StateMappingFunction<S> } |
| 37 | + ): { [key in K]: Computed }; |
34 | 38 | } |
35 | 39 |
|
36 | 40 | interface MapperForStateWithNamespace { |
37 | | - <S>( |
| 41 | + <S, T extends CompleteObject, K extends keyof T>( |
38 | 42 | namespace: string, |
39 | | - map: Dictionary<(this: typeof Vue, state: S, getters: any) => any> |
40 | | - ): Dictionary<Computed>; |
| 43 | + map: { [key in K]: StateMappingFunction<S> } |
| 44 | + ): { [key in K]: Computed }; |
41 | 45 | } |
42 | 46 |
|
43 | 47 | interface NamespacedMappers { |
|
0 commit comments