Skip to content

Commit d39791b

Browse files
authored
fix(types): allow a function type for root state option (#1132)
1 parent 404d0de commit d39791b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export interface CommitOptions {
7979
}
8080

8181
export interface StoreOptions<S> {
82-
state?: S;
82+
state?: S | (() => S);
8383
getters?: GetterTree<S, S>;
8484
actions?: ActionTree<S, S>;
8585
mutations?: MutationTree<S>;

types/test/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ namespace RootDefaultModule {
9898
});
9999
}
100100

101+
namespace InitialStateFunction {
102+
const store = new Vuex.Store({
103+
state: () => ({
104+
value: 1
105+
})
106+
});
107+
const n: number = store.state.value;
108+
}
109+
101110
namespace NestedModules {
102111
interface RootState {
103112
a: {

0 commit comments

Comments
 (0)