Skip to content

Generate store type from vuex-simple #30

@sobolevn

Description

@sobolevn
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions