|
@@ -1,51 +1,68 @@
|
|
import Vue from 'vue';
|
|
import Vue from 'vue';
|
|
import { Dispatch, Commit } from './index';
|
|
import { Dispatch, Commit } from './index';
|
|
|
|
|
|
-type Dictionary<T> = { [key: string]: T };
|
|
|
|
type Computed = () => any;
|
|
type Computed = () => any;
|
|
|
|
+type InlineComputed<T extends Function> = T extends (...args: any[]) => infer R ? () => R : never
|
|
type MutationMethod = (...args: any[]) => void;
|
|
type MutationMethod = (...args: any[]) => void;
|
|
type ActionMethod = (...args: any[]) => Promise<any>;
|
|
type ActionMethod = (...args: any[]) => Promise<any>;
|
|
-type CustomVue = Vue & Dictionary<any>;
|
|
|
|
|
|
+type InlineMethod<T extends (fn: any, ...args: any[]) => any> = T extends (fn: any, ...args: infer Args) => infer R ? (...args: Args) => R : never
|
|
|
|
+type CustomVue = Vue & Record<string, any>;
|
|
|
|
|
|
interface Mapper<R> {
|
|
interface Mapper<R> {
|
|
- (map: string[]): Dictionary<R>;
|
|
|
|
- (map: Dictionary<string>): Dictionary<R>;
|
|
|
|
|
|
+ <Key extends string>(map: Key[]): { [K in Key]: R };
|
|
|
|
+ <Map extends Record<string, string>>(map: Map): { [K in keyof Map]: R };
|
|
}
|
|
}
|
|
|
|
|
|
interface MapperWithNamespace<R> {
|
|
interface MapperWithNamespace<R> {
|
|
- (namespace: string, map: string[]): Dictionary<R>;
|
|
|
|
- (namespace: string, map: Dictionary<string>): Dictionary<R>;
|
|
|
|
|
|
+ <Key extends string>(namespace: string, map: Key[]): { [K in Key]: R };
|
|
|
|
+ <Map extends Record<string, string>>(namespace: string, map: Map): { [K in keyof Map]: R };
|
|
}
|
|
}
|
|
|
|
|
|
-interface FunctionMapper<F, R> {
|
|
|
|
- (map: Dictionary<(this: CustomVue, fn: F, ...args: any[]) => any>): Dictionary<R>;
|
|
|
|
|
|
+interface MapperForState {
|
|
|
|
+ <S, Map extends Record<string, (this: CustomVue, state: S, getters: any) => any> = {}>(
|
|
|
|
+ map: Map
|
|
|
|
+ ): { [K in keyof Map]: InlineComputed<Map[K]> };
|
|
}
|
|
}
|
|
|
|
|
|
-interface FunctionMapperWithNamespace<F, R> {
|
|
|
|
- (
|
|
|
|
|
|
+interface MapperForStateWithNamespace {
|
|
|
|
+ <S, Map extends Record<string, (this: CustomVue, state: S, getters: any) => any> = {}>(
|
|
namespace: string,
|
|
namespace: string,
|
|
- map: Dictionary<(this: CustomVue, fn: F, ...args: any[]) => any>
|
|
|
|
- ): Dictionary<R>;
|
|
|
|
|
|
+ map: Map
|
|
|
|
+ ): { [K in keyof Map]: InlineComputed<Map[K]> };
|
|
}
|
|
}
|
|
|
|
|
|
-interface MapperForState {
|
|
|
|
- <S>(
|
|
|
|
- map: Dictionary<(this: CustomVue, state: S, getters: any) => any>
|
|
|
|
- ): Dictionary<Computed>;
|
|
|
|
|
|
+interface MapperForAction {
|
|
|
|
+ <Map extends Record<string, (this: CustomVue, dispatch: Dispatch, ...args: any[]) => any>>(
|
|
|
|
+ map: Map
|
|
|
|
+ ): { [K in keyof Map]: InlineMethod<Map[K]> };
|
|
}
|
|
}
|
|
|
|
|
|
-interface MapperForStateWithNamespace {
|
|
|
|
- <S>(
|
|
|
|
|
|
+interface MapperForActionWithNamespace {
|
|
|
|
+ <Map extends Record<string, (this: CustomVue, dispatch: Dispatch, ...args: any[]) => any>>(
|
|
|
|
+ namespace: string,
|
|
|
|
+ map: Map
|
|
|
|
+ ): { [K in keyof Map]: InlineMethod<Map[K]> };
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+interface MapperForMutation {
|
|
|
|
+ <Map extends Record<string, (this: CustomVue, commit: Commit, ...args: any[]) => any>>(
|
|
|
|
+ map: Map
|
|
|
|
+ ): { [K in keyof Map]: InlineMethod<Map[K]> };
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+interface MapperForMutationWithNamespace {
|
|
|
|
+ <Map extends Record<string, (this: CustomVue, commit: Commit, ...args: any[]) => any>>(
|
|
namespace: string,
|
|
namespace: string,
|
|
- map: Dictionary<(this: CustomVue, state: S, getters: any) => any>
|
|
|
|
- ): Dictionary<Computed>;
|
|
|
|
|
|
+ map: Map
|
|
|
|
+ ): { [K in keyof Map]: InlineMethod<Map[K]> };
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
interface NamespacedMappers {
|
|
interface NamespacedMappers {
|
|
mapState: Mapper<Computed> & MapperForState;
|
|
mapState: Mapper<Computed> & MapperForState;
|
|
- mapMutations: Mapper<MutationMethod> & FunctionMapper<Commit, MutationMethod>;
|
|
|
|
|
|
+ mapMutations: Mapper<MutationMethod> & MapperForMutation;
|
|
mapGetters: Mapper<Computed>;
|
|
mapGetters: Mapper<Computed>;
|
|
- mapActions: Mapper<ActionMethod> & FunctionMapper<Dispatch, ActionMethod>;
|
|
|
|
|
|
+ mapActions: Mapper<ActionMethod> & MapperForAction;
|
|
}
|
|
}
|
|
|
|
|
|
export declare const mapState: Mapper<Computed>
|
|
export declare const mapState: Mapper<Computed>
|
|
@@ -55,15 +72,15 @@ export declare const mapState: Mapper<Computed>
|
|
|
|
|
|
export declare const mapMutations: Mapper<MutationMethod>
|
|
export declare const mapMutations: Mapper<MutationMethod>
|
|
& MapperWithNamespace<MutationMethod>
|
|
& MapperWithNamespace<MutationMethod>
|
|
- & FunctionMapper<Commit, MutationMethod>
|
|
|
|
- & FunctionMapperWithNamespace<Commit, MutationMethod>;
|
|
|
|
|
|
+ & MapperForMutation
|
|
|
|
+ & MapperForMutationWithNamespace;
|
|
|
|
|
|
export declare const mapGetters: Mapper<Computed>
|
|
export declare const mapGetters: Mapper<Computed>
|
|
& MapperWithNamespace<Computed>;
|
|
& MapperWithNamespace<Computed>;
|
|
|
|
|
|
export declare const mapActions: Mapper<ActionMethod>
|
|
export declare const mapActions: Mapper<ActionMethod>
|
|
& MapperWithNamespace<ActionMethod>
|
|
& MapperWithNamespace<ActionMethod>
|
|
- & FunctionMapper<Dispatch, ActionMethod>
|
|
|
|
- & FunctionMapperWithNamespace<Dispatch, ActionMethod>;
|
|
|
|
|
|
+ & MapperForAction
|
|
|
|
+ & MapperForActionWithNamespace;
|
|
|
|
|
|
export declare function createNamespacedHelpers(namespace: string): NamespacedMappers;
|
|
export declare function createNamespacedHelpers(namespace: string): NamespacedMappers;
|