From 223c00e35809831076b5f4fb0021c65f2b6db73c Mon Sep 17 00:00:00 2001 From: ktsn Date: Thu, 11 Jan 2018 23:45:07 +0900 Subject: [PATCH] fix(types): allow a function type for root `state` option --- types/index.d.ts | 2 +- types/test/index.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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: {