question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

separating getters and actions to dedicated files break typing of `this`

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

10reactions
vycodercommented, Jul 25, 2021

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?

1reaction
posvacommented, Jan 26, 2021

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#L216

Some of them can be inferred with ReturnType<typeof state> but you will need to manually do G and A for getters and actions

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found