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

Ensure more accurate TData TypeScript types for useSuspenseQuery #10713

Closed
jerelmiller opened this issue Apr 3, 2023 · 2 comments · Fixed by #10766
Closed

Ensure more accurate TData TypeScript types for useSuspenseQuery #10713

jerelmiller opened this issue Apr 3, 2023 · 2 comments · Fixed by #10766

Comments

@jerelmiller
Copy link
Member

jerelmiller commented Apr 3, 2023

Currently useSuspenseQuery sets the returned data property to type TData (a generic). This works well with the default behavior since the hook will throw errors when encountered.

There are however a couple cases that will cause data to remain undefined.

  1. Setting errorPolicy to anything other than none (the default). If an error is encountered with all or ignore, the error is not thrown and is expected to be handled locally, but data might not be set.
  2. Setting skip to true (Support skip in useSuspenseQuery #10532). Once this is supported, skip will not load any data, so data is expected to be undefined until skip is false.

Additionally, setting returnPartialData may result in some of missing data. In this case, we should set data to DeepPartial<TData> (note DeepPartial is not a part of TypeScript: we'll need a helper) to better communicate that the data type might not contain all the required values.

In short, our types should reflect the following:

  • errorPolicy: 'none' -> data: TData
  • errorPolicy: 'ignore' -> data: TData | undefined
  • errorPolicy: 'all' -> data: TData | undefined
  • skip: false -> data: TData
  • skip: true -> data: TData | undefined
  • returnPartialData: true -> data: DeepPartial<TData>
  • returnPartialData: false -> data: TData
@jerelmiller
Copy link
Member Author

Fixed in #10766

@github-actions
Copy link
Contributor

github-actions bot commented Jun 2, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
1 participant