-
-
Notifications
You must be signed in to change notification settings - Fork 171
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
Setting an object through MutateAction throws an exception #382
Comments
I think that the issue is that the Mutations' return value must ONLY have a STRICT SUBSET of the keys in the module's state. Unfortunately, this isn't actually something that can be expressed in TypeScript's type system. TypeScript interfaces and types only describes a "minimum" requirement for a value to satisfy. To fix that problem, your
However, I would also suggest that you maybe narrow your MutationActions' return types. Technically |
Fair, however when I pass an object that matches the spec, which the TypeScript type does force off in type checking at least, it still throws this same error. |
Can you show the exact calling code? Are you accessing the store through the component plugin thing with I don't really know how TS decorators/annotations work, nor exactly how this library implements these annotations, but I wonder if what might be happening is that the action is being transformed at compile time in such a way that it's including the fields of the Partial type in the action payload, even if they're undefined at runtime. Honestly... I've stopped using this library. It is too much magic and it doesn't really work as expected- partly because TypeScript's typing can't actually be used to type the actions and mutations correctly (as I pointed out above), but also because the library itself has a few inconsistencies and bugs (like the getModule function). It was less painful to just suck it up and write my store the "default" way. I'm fairly close to giving up on the class component library for similar reasons... |
Using the following module code:
Then using it in a Vue module, and calling
getObject
successfully sets the valObject from the API call's response.However calling
applyState({ valObject: { test: 'yes' } })
causes theERR_MUTATE_PARAMS_NOT_IN_PAYLOAD
exception to be thrown.Adding a
console.log('Apply state', state)
before the return does work properly, and returns the object in vue's Observer shell. However I still receive the same exception message. The exception itself also isn't very clear what param(s) it does trip over, so it's a bit difficult to track down outside of stepping through the code manually.The text was updated successfully, but these errors were encountered: