typescriptvue.jsapolloquasar-frameworkvetur

Object is of type 'unknown'.Vetur(2571) when populating a constant in TypeScript using Apollo


I am using the useQuery (from Apollo) to fetch data as follows:

const {
  result: fetchedResources,
  loading: fetchResourcesLoading,
  refetch: fetchResources,
  onError: apiError
} = useQuery(GET_RESOURCES, { limit: numberOfResults.value })

I use fetchedResources in a v-for to loop over data:

  <router-link
    v-for="resource in fetchedResources.resources"
    :key="resource.id"
    class="resource q-mb-md items-center text-black"
    tag="div"
  >
...

Any time I use resource I get the following error in Visual Studio:

Object is of type 'unknown'.Vetur(2571)

I assume the issue is I need to declare the type in the constant for each of the populate variables. Any ideas how to resolve this?


Solution

  • Looks like Vetur has recently released 0.35.0 and it picked up a genuine error in the Typescript code for Apollo. These docs provided info on how to set the type for each array: https://www.apollographql.com/docs/react/development-testing/static-typing/