Преглед на файлове

fix(types): allow a function type for root `state` option (#1132)

katashin преди 6 години
родител
ревизия
d39791bd05
променени са 2 файла, в които са добавени 10 реда и са изтрити 1 реда
  1. 1 1
      types/index.d.ts
  2. 9 0
      types/test/index.ts

+ 1 - 1
types/index.d.ts

@@ -79,7 +79,7 @@ export interface CommitOptions {
 }
 }
 
 
 export interface StoreOptions<S> {
 export interface StoreOptions<S> {
-  state?: S;
+  state?: S | (() => S);
   getters?: GetterTree<S, S>;
   getters?: GetterTree<S, S>;
   actions?: ActionTree<S, S>;
   actions?: ActionTree<S, S>;
   mutations?: MutationTree<S>;
   mutations?: MutationTree<S>;

+ 9 - 0
types/test/index.ts

@@ -98,6 +98,15 @@ namespace RootDefaultModule {
   });
   });
 }
 }
 
 
+namespace InitialStateFunction {
+  const store = new Vuex.Store({
+    state: () => ({
+      value: 1
+    })
+  });
+  const n: number = store.state.value;
+}
+
 namespace NestedModules {
 namespace NestedModules {
   interface RootState {
   interface RootState {
     a: {
     a: {