separating getters and actions to dedicated files break typing of `this`
See original GitHub issueI want to separate my getters and actions to dedicated files instead of just put them all together in one store file, like this:
import { defineStore } from 'pinia'
import { state } from './state'
import { getters } from './getters'
import { actions } from './actions'
export const useMainStore = defineStore({
id: 'main',
state: () => state,
getters,
actions,
})
But in the getters and actions file, I can not use this
to reference the store object now.
What should I do for such a situation?
Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
separating getters and actions to dedicated files break typing ...
I want to separate my getters and actions to dedicated files instead of just put them all together in one store file, like...
Read more >Separating store into separate files (actions, mutations, getters ...
I'm trying to spilt up my store firstly so all the getters, actions and mutations are in separate files as per this answer: ......
Read more >Vuex - GitLab Docs
Separation of concerns. Vuex is composed of State, Getters, Mutations, Actions, and Modules. When a user selects an action, we need to dispatch...
Read more >Code Refactorings for C# & .NET - Features | ReSharper
This refactoring can be applied to a single file or a selection of files that have multiple types each. ReSharper creates dedicated files...
Read more >ECMAScript® 2023 Language Specification - TC39
Introduction. This Ecma Standard defines the ECMAScript 2023 Language. It is the fourteenth edition of the ECMAScript Language Specification.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @posva, if it’s not too much to ask, can you provide an example (or even include it in the documentation) of how to properly type
this
when splitting them into their own separate files?You will have to manually type
this
using the Store type and creating types for each of its generics https://github.com/posva/pinia/blob/fc56acb41e3753ddc8aef965d3d78bfac4f93db5/src/store.ts#L216Some of them can be inferred with
ReturnType<typeof state>
but you will need to manually doG
andA
for getters and actions