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

Time:01-05

I get errors like this in the console:

  • TS2339: Property 'shop' does not exist on type '(Ref<never[]> | ((id: number) => Promise))[]'.
  • TS2339: Property 'getShop' does not exist on type '(Ref<never[]> | ((id: number) => Promise))[]'.

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 {}
  },
})

CodePudding user response:

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] =).

  •  Tags:  
  • Related