Access State by using Vuex getter functions with TypeScript

Share this video with your friends

Send Tweet

Accessing state directly can be ok for some cases, but in others we need another representation of state.

This lesson will show you how Vuex getters solve that issue and how to type-safe these getters with TypeScript using the @Getter decorator.

haris
haris
~ 4 years ago

What is the advantage of using @Getter instead of :

get dones {
   return this.$store.getters.dones
}
Alex Jover Morales
Alex Jover Moralesinstructor
~ 4 years ago

Just convenience, under the hood it does something like that. Decorators make it more declarative and easier to type.

Ali Anwar
Ali Anwar
~ 3 years ago

Hi, I'm following the lesson, but I'm getting "Property 'todos' has no initializer and is not definitely assigned in the constructor.", unless I declare it like this @Getter todos!: Todo[];, and I wonder if this the proper way of doing it?

Gala Calero
Gala Calero
~ a year ago

I'm having the same issue as Ali, it's a good question.