Skip to content

Autocomplete in VSCode: show only my state and actions? #937

Discussion options

You must be logged in to vote

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;

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by rodrigocfd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant