[Vuejs]-Property does not exist in this type

1👍

This issue happens because your component’s current_category, filterByCategory function and services isn’t recognized by TypeScript. These functions can be added by using the interface. You need to define these types first like this.

interface MyComponent {
  current_category: string;
  filterByCategory(array: any): any;
  services: any[];
  filteredProducts(): any;
}

export default {
  name: 'HomePage',
  components: {},
  methods: {
    filterByCategory(array: any) {
      return array.filter((service: any) => service.type == this.current_category);
    }
  },
  data(): MyComponent {
    return {
      current_category: "xxx",
      services: [],
      filteredProducts() {
        return this.filterByCategory(this.services);
      }
    };
  },
  mounted() {},
};

Leave a comment