vuex
vuex copied to clipboard
feat(types): strictly typed
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
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)
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.
@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
// 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.