Goryyn
Goryyn

Reputation: 383

Property does not exist on type 'Ref<never[]>[]'

I get errors like this in the console:

Why do they arise? How do I fix them?Sample code:

// useShop.ts
import { ref } from "vue"

export default function useShop() {
  const shop = ref([])

  const getShop = async (id: number) => {
    // get data...
    shop.value = []
  }

  return [shop, getShop]
}

// Detail.vue
export default defineComponent({
  components: {},
  setup() {
    const { shop, getShop } = useShop()
    return {}
  },
})

Upvotes: 2

Views: 2418

Answers (1)

idmean
idmean

Reputation: 14895

You return an array here:

return [shop, getShop]

and use object destructuring here:

const { shop, getShop } = useShop()

Either return an object ({shop, getShop}) or use array destructuring (const [shop, getShop] =).

Upvotes: 2

Related Questions