Skip to content

feat(types): strictly typed - #1953

Open
kotamat wants to merge 3 commits into
vuejs:mainfrom
kotamat:4.0_improve_type
Open

kotamat wants to merge 3 commits into
vuejs:mainfrom
kotamat:4.0_improve_type

Conversation

@kotamat

@kotamat kotamat commented Mar 22, 2021

Copy link
Copy Markdown

Using StoreObject instead of State allows for more
type-safe calls to the Vuex API from client.

  • store.dispatch(), store.commit() has namespaced-typed params and their payloads
    • the params links to definition on VS Code
  • The inside of StoreObject-calls(ex, commit()) may have
    any type
  • mapXxx() are not changed.
  • Not supported root, namespaced flags

4f3d2b20c56f96ba1e23a6b9a77c60e7
34510fb278105f5d3e755a367be76eeb

and changed code formats.

Please see

  • the naming( because of poor English skill..)
  • formats ( default prettier format attached )
  • some omissions (don't know well whole Vuex codes)

Using StoreObject instead of State allows for more
type-safe calls to the Vuex API from client.
* The inside of StoreObject-calls(ex,  commit()) may have
  `any` type
* mapXxx() are not changed.
@tommie

tommie commented Apr 6, 2021

Copy link
Copy Markdown

Drive-by comment: thanks for working on this! I don't understand the generics involved in ExtractObjects, but I'm wondering if it would be possible to skip the separate S type param to useStore and also extract that from SO?

You retracted pull/1943, which seems to be the same thing, but doing the above S extraction (and splitting off the reformatting from the individual changes). I'm just curious why you replaced the PR.

@kotamat

kotamat commented Apr 6, 2021 •

Copy link
Copy Markdown
Author

@tommie
ExtractObjects transforms StoreObject to useful type for args/return-value of dispatch() and commit().
like this

const s = {
  modules: {
    foo: {
      modules: {
        hoge: {
          actions: {
            bar: (n: number) => "aaa",
          },
        },
      },
    },
    bar: {
      actions: {
        bal: (x: string) => "aaa",
      },
    },
  },
};

to

{
  "bar/bal": (x: string) => string,
  "foo/hoge/bar": (n: number) => string
}

I'm wondering if it would be possible to skip the separate S type param to useStore and also extract that from SO?

Yes.

You can skip like this
22e706a7818996ead6cda631dc8788e3

// store is instance of vuex
  const key: InjectionKey<typeof store> = Symbol('key')
  const usedStore = Vuex.useStore(key)

You retracted pull/1943, which seems to be the same thing, but doing the above S extraction (and splitting off the reformatting from the individual changes). I'm just curious why you replaced the PR.

Initially, I have intended to send out the PR to my repo, but I made a mistake and created 1943. So, I reflexively closed it.
Then, I have finished the changes, cleaned-up the commit messages and made this PR.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants