-
Notifications
You must be signed in to change notification settings - Fork 38
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
Add Vuex typescript recipe example #61
Conversation
recipes/typescript.md
Outdated
<details><summary>Vuex client</summary> | ||
|
||
```ts | ||
type State = number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s use a more real example of having object in the state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reduced code to be like Redux example 🤦🏻♀️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeap, I will update Redux example too. I did the same mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s wait for new Redux example to have the same store in the Vuex example
recipes/typescript.md
Outdated
let store = new Logux.Store<State>({ | ||
state: 0, | ||
mutations: { | ||
increment (state) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need an example of mutation with parameters
recipes/typescript.md
Outdated
} | ||
}) | ||
|
||
store.commit.sync<IncrementMutation>({ type: 'increment' }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need IncrementMutation
template here?
Can we pass available actions to the Logux.Store
to check types in commit.sync
? It will dramatically reduce code size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking for solution with @nikolay-govorov. We can use decorators or something like vuex-type-helper. I haven't tried that. It seems redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My solution I took from Vuex's issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this is not a problem with the @logux/vuex
binding, but with the Vuex itself. In Vuex v4, deeper support for TS is expected, and I believe it will be possible to type not only the state but also the signatures of actions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is fixed Redux example 2609816
I think passing IncrementMutation
to store.commit.sync
does not any useful. It will be better just recommend some good action creator library.
I made example like Redux and simplified it. We'll improve it in the near future, as discussed. |
@ai, can be merged, I think. |
Resolve logux/vuex#7
Only this way you can use TS in Vuex 3 without decorators or other modules. Other ways are too specific. That's should be enough for today's documentation.