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

Generate store type from vuex-simple #30

Open
sobolevn opened this issue Jun 26, 2019 · 2 comments
Open

Generate store type from vuex-simple #30

sobolevn opened this issue Jun 26, 2019 · 2 comments

Comments

@sobolevn
Copy link
Contributor

  • I'm submitting a ...
    [ ] bug report
    [x] feature request
    [x] question about the decisions made in the repository
    [x] question about how to use this project

  • Summary

There are cases where you need Store<StateType> directly.
And there's no way to write it.

When we use vuex-simple we write classes instead of a regular Store, and we do not have this StateType, since it is bundled with other methods, getters, etc.

What do I suggest?

import { State, Module, StateTypeOf } from 'vuex-simple'

class CommentsModule {
  @State()
  public comments: CommentType[] = []
}

class TypedStore {
  @Module()
  public comments = new CommentsModule()
}

type StateType = StateTypeOf<typeof TypedStore>

And later it can be used for Store<StateType>. This way we have the best from the bosth worlds. Native types and no code duplication.

Similar approach: https://github.com/gcanti/io-ts#typescript-integration

@sobolevn
Copy link
Contributor Author

@sobolevn
Copy link
Contributor Author

This might be interesting to you: wemake-services/wemake-vue-template#1197

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

No branches or pull requests

1 participant