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

TS2551 error when calling an action from within a getter #2198

Closed
Farnsi opened this issue May 12, 2023 · 1 comment
Closed

TS2551 error when calling an action from within a getter #2198

Farnsi opened this issue May 12, 2023 · 1 comment

Comments

@Farnsi
Copy link

Farnsi commented May 12, 2023

Reproduction

https://github.com/piniajs?q=example&type=source

Steps to reproduce the bug

TS error 2551

Property 'callAnAction' does not exist on type '{ aStateVariable: boolean } & PiniaCustomStatePr...'. ts(2551)

I use vuetifys v-switch, which uses a v-model that i map with mapWritableState

Some Template:

...mapWritableState(myStore, ['aStateVariable', ...

To detect when the var changes, i use a getter and call an action

The Store:

  state: () => ({
    aStateVariable: true
  }),
  getters: {
    myGetter(state) {
      if (state.aStateVariable) {
        state.callAnAction()
              ^^^^^^^^^^^^ TS(2551)
      }
    },
  },
  actions: {
    callAnAction() {
      console.log('i got called')
    }
  }

The code works, but i got the TS error

Expected behavior

No error, or an explanation, that it is prohibited to call an action from a getter.

Actual behavior

TS error

Additional information

No response

Copy link
Member

posva commented May 12, 2023

This is intended. No side effects in getters

@posva posva closed this as not planned Won't fix, can't repro, duplicate, stale May 12, 2023
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

2 participants