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