Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading