Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(types): strictly typed #1953

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

kotamat
Copy link

@kotamat kotamat commented Mar 22, 2021

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
Copy link

tommie commented Apr 6, 2021

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
Copy link
Author

kotamat commented Apr 6, 2021

@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.

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