Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Computed Vue Property with Getter & Setter won't compile in Webpack

I'm attempting to convert an app that was in development with just Javascript over to Typescript. I've ran into a problem I can't seem to solve. I have a computed property with a getter and a setter that won't compile when run through Webpack. I am not using the class decorator way of declaring components and am instead using the object literal syntax.

import Vue from "vue"

export default Vue.extend({
  computed: {
   prioritized: {
    get(): any[] {
     return this.$store.getters["blah"];
    }
    set(value): void {
     //set value here
    }
   }
  }
})

Below is the first error webpack gives me:

ERROR in ~listHome.ts(30,29) TS2339: Property '$store' does not exist on type '{ get(): any[]; set(value: unknown): void; }'.

I'm pretty new to Typescript to be honest, so I may be missing something simple here in my frustration of porting this app over.

like image 830
Richard Cawthon Avatar asked Aug 01 '19 21:08

Richard Cawthon


1 Answers

Wow, figured it out.

I was missing the type declaration for "value" and it broke everything. FUN

        get(): any[] {
            return this.$store.getters["homeList/sortedPriority"];
        },
        set(value:any): void {
            var test = 1;
        }
like image 75
Richard Cawthon Avatar answered Sep 18 '22 05:09

Richard Cawthon