You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sorry I'm not going to spend several hours making a minimal demo project and uploading it to github just to have 8 letters added. The error and fix should be obvious.
// src/datamodel/appstore.tsclassTAppStore{counter: number=0;};exportvarAppStore=newVuex.Store<TAppStore>({state: function(){console.log('creating AppStore');//gets called just finereturnnewTAppStore();}}
What is expected?
No errors reported on compilation.
What is actually happening?
ERROR in j:\types\CML\front\src\datamodel\appstore.ts
[tsl] ERROR in j:\types\CML\front\src\datamodel\appstore.ts(44,2)
TS2345: Argument of type '{ state: () => TAppStore; }' is not assignable to parameter of type 'StoreOptions<TAppStore>'.
Types of property 'state' are incompatible.
Type '() => TAppStore' is not assignable to type 'TAppStore | undefined'.
Type '() => TAppStore' is not assignable to type 'TAppStore'.
Property 'counter' is missing in type '() => TAppStore'.
Build failed with errors.
It seems that vuex/types/index.d.ts, in interface StoreOptions, is missing the possibility of using a function instead of an object.
This is the recommended way to initialize state: https://vuex.vuejs.org/en/modules.html (chapter Module Reuse, at the very bottom).
An easy fix would be editing the vuex/types/index.d.ts StoreOptions:
Version
3.0.1
Reproduction link
https://codesandbox.io/s/l2wzjwp4vm
Steps to reproduce
Sorry I'm not going to spend several hours making a minimal demo project and uploading it to github just to have 8 letters added. The error and fix should be obvious.
What is expected?
No errors reported on compilation.
What is actually happening?
It seems that vuex/types/index.d.ts, in interface StoreOptions, is missing the possibility of using a function instead of an object.
This is the recommended way to initialize state: https://vuex.vuejs.org/en/modules.html (chapter Module Reuse, at the very bottom).
An easy fix would be editing the vuex/types/index.d.ts StoreOptions:
export interface StoreOptions<S> { - state?: S; state?: S|(()=>S); getters?: GetterTree<S, S>; actions?: ActionTree<S, S>; mutations?: MutationTree<S>; modules?: ModuleTree<S>; plugins?: Plugin<S>[]; strict?: boolean; }
The text was updated successfully, but these errors were encountered: