diff --git a/types/index.d.ts b/types/index.d.ts index 70da30c1e..4c029ccdb 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -77,7 +77,7 @@ export interface CommitOptions { } export interface StoreOptions { - state?: S; + state?: S | (() => S); getters?: GetterTree; actions?: ActionTree; mutations?: MutationTree; diff --git a/types/test/index.ts b/types/test/index.ts index 0253e5df8..4a985926b 100644 --- a/types/test/index.ts +++ b/types/test/index.ts @@ -96,6 +96,15 @@ namespace RootDefaultModule { }); } +namespace InitialStateFunction { + const store = new Vuex.Store({ + state: () => ({ + value: 1 + }) + }); + const n: number = store.state.value; +} + namespace NestedModules { interface RootState { a: {