Skip to content

The types do not signal that the result can be undefined #1073

Open
@kpilard

Description

@kpilard

Describe the bug
At the moment is the result of useQuery defined as Ref<TResult>. But shouldn't it be Ref<undefined|TResult>.
While the Query is executed result.value will be undefined.

Example

setup () {
  const {result} = useQuery<UsePostsResult>()
  const posts = computed(() => result.value.posts)

  return {posts}
}

This example would create an error, because undefined.posts is not available. The typescript check doesn't notice this error because result.value is defined to be UsePostsResult.

Expected behavior
The result should be marked as possibly undefined.

Versions
vue: 2.6.11
vue-apollo: 4.0.0-alpha.10
apollo-client: 2.6.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions