Skip to content

Commit 7c7ed1d

Browse files
HerringtonDarkholmektsn
authored andcommitted
fix: fix #1032, relax vue typing in helpers (#1044)
1 parent ca64c3f commit 7c7ed1d

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

types/helpers.d.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type Dictionary<T> = { [key: string]: T };
55
type Computed = () => any;
66
type MutationMethod = (...args: any[]) => void;
77
type ActionMethod = (...args: any[]) => Promise<any>;
8+
type CustomVue = Vue & Dictionary<any>
89

910
interface Mapper<R> {
1011
(map: string[]): Dictionary<R>;
@@ -17,26 +18,26 @@ interface MapperWithNamespace<R> {
1718
}
1819

1920
interface FunctionMapper<F, R> {
20-
(map: Dictionary<(this: typeof Vue, fn: F, ...args: any[]) => any>): Dictionary<R>;
21+
(map: Dictionary<(this: CustomVue, fn: F, ...args: any[]) => any>): Dictionary<R>;
2122
}
2223

2324
interface FunctionMapperWithNamespace<F, R> {
2425
(
2526
namespace: string,
26-
map: Dictionary<(this: typeof Vue, fn: F, ...args: any[]) => any>
27+
map: Dictionary<(this: CustomVue, fn: F, ...args: any[]) => any>
2728
): Dictionary<R>;
2829
}
2930

3031
interface MapperForState {
3132
<S>(
32-
map: Dictionary<(this: typeof Vue, state: S, getters: any) => any>
33+
map: Dictionary<(this: CustomVue, state: S, getters: any) => any>
3334
): Dictionary<Computed>;
3435
}
3536

3637
interface MapperForStateWithNamespace {
3738
<S>(
3839
namespace: string,
39-
map: Dictionary<(this: typeof Vue, state: S, getters: any) => any>
40+
map: Dictionary<(this: CustomVue, state: S, getters: any) => any>
4041
): Dictionary<Computed>;
4142
}
4243

types/test/helpers.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ new Vue({
4141
k: "k"
4242
}),
4343
helpers.mapState({
44-
k: (state: any, getters: any) => state.k + getters.k
44+
k: (state: any, getters: any) => state.k + getters.k,
45+
useThis(state: any, getters: any) {
46+
return state.k + getters.k + this.whatever
47+
}
4548
}),
4649

4750
helpers.mapGetters(["l"]),

0 commit comments

Comments
 (0)