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

Export StoreWithState interface #339

Closed
LadislavBohm opened this issue Jan 20, 2021 · 5 comments
Closed

Export StoreWithState interface #339

LadislavBohm opened this issue Jan 20, 2021 · 5 comments
Labels
feature request v1 issues related to v1 for Vue 2

Comments

@LadislavBohm
Copy link

What problem is this solving

I am trying to create generic function for creating base stores. Something like this

interface BaseState {
  baseData: ""
};

function defineEnumerationStore<TEnumeration, TAdditionalState, TAdditionalActions>(id: string, additionalState?: TAdditionalState, additionalActions?: TAdditionalActions) {
  return defineStore({
    id: "...",
    state: () => ({
      baseData: "",
      ...additionalState
    } as BaseState & TAdditionalState),
    actions: {
      baseMethod() {
        return this.baseData;
      },
      ...additionalActions
    } //here I can't type actions object like StoreWithState<> & TAdditionalActions
  })
}

I want to be able to provide additional actions and state data to this generic function. My problem is that I can't type my extended actions object like shown in the code above. Maybe I am doing it wrong way, but I think it would help if StoreWithState interface was exported so I can use it to type my actions object.

Proposed solution

Export type:
interface StoreWithState<Id extends string, S extends StateTree>

@posva posva added the v1 issues related to v1 for Vue 2 label Jan 20, 2021
@posva
Copy link
Member

posva commented Jan 20, 2021

PR welcome! v2 already does that

@posva
Copy link
Member

posva commented Jan 20, 2021

I will have to release a version soon for v2 for the exposed types

@LadislavBohm
Copy link
Author

I completely missed 2.0.0-alpha.6 version that already has them exported 🤦‍♂️ as I was using 2.0.0-alpha.5, will try to make a PR for version one today at least.

@LadislavBohm
Copy link
Author

I don't understand what happened but in my 2.0.0-alpha.5 types were not exported but I can see that they were exported in both v1 and v2 branches long time ago. So I believe there is no need for PR, sorry for the confusion.

posva added a commit that referenced this issue Jan 22, 2021
@posva
Copy link
Member

posva commented Jan 22, 2021

I pushed a commit to expose the types to v1 and will release the next week or so after adding other changes to align as much as possible with v2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request v1 issues related to v1 for Vue 2
Projects
None yet
Development

No branches or pull requests

2 participants