How do I type a stor if _GettersTree is marked as for internal use only? #751
Answered
by
BenShelton
Azema4ka
asked this question in
Help and Questions
-
The ProblemI used Example of using the store with
|
Beta Was this translation helpful? Give feedback.
Answered by
BenShelton
Nov 14, 2021
Replies: 1 comment 3 replies
-
TS can infer the types without you having to specify them all. This should be all you need: interface State {
list: Apartment[];
}
export const useApartmentsStore = defineStore(
"apartments-pinia",
{
state: (): State => ({
list: [],
}),
getters: {
getById: (state) => (id: string) => state.list.find((apartment) => apartment.id === id),
},
}
); I also converted the state function to an arrow function as it improves type safety for some, see https://pinia.esm.dev/core-concepts/state.html#state |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
Azema4ka
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TS can infer the types without you having to specify them all. This should be all you need:
I also converted the state function to an arrow function as it improves type safety for some, see https://pinia.esm.dev/core-concepts/state.html#state