Autocomplete in VSCode: show only my state and actions? #937
Answered
by
rodrigocfd
rodrigocfd
asked this question in
Help and Questions
-
I'm using Pinia with TypeScript and Vue 3, full Composition API. The autocomplete in VSCode shows a lot of stuff: Is there a way to filter out only the stuff I wrote (just my state and actions)? I'm aware of storeToRefs, which filters only the state, but then there's no way to access the actions. |
Beta Was this translation helpful? Give feedback.
Answered by
rodrigocfd
Jan 7, 2022
Replies: 1 comment
-
So after a lot of head-scratching I managed to write something that does exactly what I need. Maybe it's useful to someone else, so I'm sharing it here: import {ref} from 'vue';
import {defineStore, StoreActions, StoreGetters, StoreState} from 'pinia';
const useDef = defineStore('main', () => {
const name = ref('joe');
const age = ref(80);
return {
name,
age,
getOlder(years: number) {
age.value += years;
},
};
});
export type ReachableStore =
StoreActions<ReturnType<typeof useDef>> &
StoreGetters<ReturnType<typeof useDef>> &
StoreState<ReturnType<typeof useDef>>;
const useStore = (): ReachableStore => useDef();
export default useStore; |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
rodrigocfd
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So after a lot of head-scratching I managed to write something that does exactly what I need.
Maybe it's useful to someone else, so I'm sharing it here: