Wrong type of argument to getters in options mode with typescript #1837
Unanswered
jhughes-dev
asked this question in
Help and Questions
Replies: 1 comment
-
Any help here? I've run into the same problem. It does not seem like expected behavior, I'm not sure why the original bug was turned into a discussion. What would be the correct way to strongly type both state and getters? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Reproduction
See Store Below
Steps to reproduce the bug
While trying to specify the types to get auto-suggestions when using the store within action and getter functions, I tried defining the types explicitly. My actual store as many actions/getters, so it made sense to separate these into different files, but I still wanted the good DX from VSCODE. Trying to make that happen, I found an issue with the type of the getter input. Add the following to a vue3+typescript project.
Expected behavior
I would expect that StoreType should work as the input to both getters and the $patch function input without error
Actual behavior
I see this error:
Additional information
Note, I can change the type of the getter function from "StoreType" to "State" and it will compile, but other getters don't show up as suggestions in VSCode and if I try to use them, typescript complains.
However, if I debug or use base javascript, I can access other getters from within the getter function or action functions as properties of state/this, and they return the expected values (not the getter functions)
I have a similar problem using a $patch with a function if I try to make the argument "StoreType" instead of "State" and again, I should be able to access getters from within a patch function. (right?)
So, what should the type of the input to the getter function and $patch function be. I would assume:
where
Beta Was this translation helpful? Give feedback.
All reactions