-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add default values for useFragment generic types #10469
Conversation
🦋 Changeset detectedLatest commit: 26f0ec1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@@ -48,7 +49,10 @@ export interface UseFragmentResult<TData> { | |||
missing?: MissingTree; | |||
} | |||
|
|||
export function useFragment_experimental<TData, TVars>( | |||
export function useFragment_experimental< | |||
TData = any, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously this would be set to unknown
by default. Should we keep the same here? I changed this to any
to be a bit more in line with our current useQuery
/other hooks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I usually prefer unknown
to any
but +1 to keeping with existing hooks here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya same. I think its fine for now to be in line with the rest of Apollo.
As an aside, I'd love to consider using unknown
as the default everywhere for v4. Perhaps this change can be made there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This PR adds default types for the
useFragment
generic definitions. This improves the experience when passing generic types directly to theuseFragment
function.Currently, you can get proper types on
data
when usingTypedDocumentNode
. Take the following example:If using the generic
gql
helper, you getunknown
as expected:If, however, I want to provide my own types to
useFragment
, the current implementation forces you to provide theTArgs
type.This is rather annoying because I have to import
OperationVariables
just to useTData
.This PR ensures a default value is properly set so that I can just pass the
TData
generic and get proper types.Checklist: