Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4: mark useEventHook param as not optional #1027

Merged
merged 1 commit into from Oct 17, 2020
Merged

Conversation

rtbo
Copy link
Contributor

@rtbo rtbo commented Jul 31, 2020

useEventHook param is currently marked optional.
This disables the possibility to destructure the query/mutation results directly in the callback parameter.
For example:

const { onResult } = useQuery(document);
onResult(({ data: { queryField } }) => {
    // use queryField
});

would currently yield a typescript error:

Property 'data' does not exist on type 'ApolloQueryResult<any> | undefined'

(note the | undefined also the event is declared as const resultEvent = useEventHook<ApolloQueryResult<any>>())

This PR solves the issue.

It is safe because:

  • it only affects the type system, not the actual JS code
  • nowhere in the source tree trigger is called with an undefined value (at least not in a way allowed by the type system)
  • a possibly undefined result can still be expressed if necessary, but it has to be explicit: useEventHook<Param | undefined>()

@Akryum Akryum merged commit 1d2f4f3 into vuejs:v4 Oct 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants