direct-vuex icon indicating copy to clipboard operation
direct-vuex copied to clipboard

Fix missing return type in doc causing typescript error

Open pierreguilmin opened this issue 4 years ago • 0 comments

Hi, first a big thank you for this very nice work! :clap:

I think the p1OrDefault getter is missing its return type in the https://github.com/paroi-tech/direct-vuex#in-a-vuex-module README section:

  getters: {
-    p1OrDefault(...args) {
+    p1OrDefault(...args): string {
      const { state, getters, rootState, rootGetters } = mod1GetterContext(args)
      // Here, 'getters', 'state', 'rootGetters' and 'rootState' are typed.
      // Without 'mod1GetterContext' only 'state' would be typed.
      return state.p1 || "default"
    }
  },

Without it typescript raises:

TS7022: 'state' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

And as stated just after:

For the same reason, declare the return type of getters each time a getter context generated by moduleGetterContext is used!

pierreguilmin avatar Dec 08 '20 09:12 pierreguilmin