Skip to content

Commit

Permalink
Add default values for useFragment generic types (#10469)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller authored Jan 23, 2023
1 parent c7ccbce commit 328c58f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/wicked-dots-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@apollo/client': patch
---

Add generic type defaults when using `useFragment` to allow passing `TData` directly to the function without needing to specify `TVars`.
6 changes: 5 additions & 1 deletion src/react/hooks/useFragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {

import { useApolloClient } from "./useApolloClient";
import { useSyncExternalStore } from "./useSyncExternalStore";
import { OperationVariables } from "../../core";

export interface UseFragmentOptions<TData, TVars>
extends Omit<
Expand Down Expand Up @@ -48,7 +49,10 @@ export interface UseFragmentResult<TData> {
missing?: MissingTree;
}

export function useFragment_experimental<TData, TVars>(
export function useFragment_experimental<
TData = any,
TVars = OperationVariables
>(
options: UseFragmentOptions<TData, TVars>,
): UseFragmentResult<TData> {
const { cache } = useApolloClient();
Expand Down

0 comments on commit 328c58f

Please sign in to comment.