Access multiple stores with their name as string #1743
-
Hi, I am working on a project with multiple stores. So in my project, I export all my stores in one single module for easy access. Because I am migrating an older vuex project, the easiest solution will be to access the stores with their name as a string. The file looks like this: (@/stores/index.ts)
I need to run an action, in which the action and store name are given in a variable called object.
for stores[object.store] i get the error message:
Has anyone an idea what type I can use to access the store? Thank you for your time! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
you need |
Beta Was this translation helpful? Give feedback.
you need
object.store
to be of type'useStore1' | 'useStore2' | 'useStore3'
(instead of juststring
) for TS to figure out the type