question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Export StoreWithState interface

See original GitHub issue

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>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
LadislavBohmcommented, Jan 20, 2021

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.

0reactions
posvacommented, 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I export an interface that I have imported?
Use the import keyword to bring in something into the type declaration space (as opposed to var which brings it into the variable...
Read more >
Typescript errors with pinia 0.5.1 · Issue #504 - GitHub
... 143 | export interface StoreWithState<Id extends string, ... 251 | * Store type to build a store 252 | */ > 253...
Read more >
https://unpkg.com/next-redux-wrapper@3.0.0/src/ind...
getInitialProps wrapper got the store with state', store. ... initialProps} store={this.store} />; } }; }; export interface Config { serializeState?:
Read more >
https://cdn.jsdelivr.net/npm/pinia@0.5.3/dist/src/...
export interface PiniaPluginContext<Id extends string = string, S extends StateTree = StateTree, G extends GettersTree<S> = GettersTree<S>, A = ActionsTree> ...
Read more >
15. Strongly type our store - Angular and NgRx - GitBook
Add an interface and initial state to our spinner reducer. src/app/state/spinner.reducer.ts. export interface State {. isOn: boolean;. }.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found