对象类型为"未知"。Vetur(2571) 使用 Apollo 在 TypeScript 中填充常量时



我使用useQuery(从Apollo)获取数据如下:

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

我在v-for中使用fetchedResources来遍历数据:

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

任何时候我使用resource我得到以下错误在Visual Studio:

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

我认为问题是我需要在每个填充变量的常量中声明类型。有什么办法解决这个问题吗?

看起来Vetur最近发布了0.35.0,它在阿波罗的Typescript代码中发现了一个真正的错误。这些文档提供了如何为每个数组设置类型的信息:https://www.apollographql.com/docs/react/development-testing/static-typing/

最新更新