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
~ 7 years ago

What is the advantage of using @Getter instead of :

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

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

Ali Anwar
~ 6 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
~ 5 years ago

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