Skip to content

Conversation

yonatan2703
Copy link

Add undefined to possible cursor types in UseTRPCInfiniteQueryResult

The type definition of UseTRPCInfiniteQueryResult currently doesn't account for undefined as a possible cursor type, which can cause type inference issues when working with routes that can be used with both useQuery and useInfiniteQuery.

This PR adds undefined as a possible type for the cursor in the InfiniteData generic type parameter.

Closes #

🎯 Changes

  • Updates the type definition of UseTRPCInfiniteQueryResult to include undefined as a possible cursor type
  • This is a bug fix that improves type inference when working with dual-purpose routes (routes that can be used with both useQuery and useInfiniteQuery)

Before:

export type UseTRPCInfiniteQueryResult<TData, TError, TInput> = TRPCHookResult &
  UseInfiniteQueryResult
    InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
    TError
  >;

After:

export type UseTRPCInfiniteQueryResult<TData, TError, TInput> = TRPCHookResult &
UseInfiniteQueryResult
  InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null | undefined>,
  TError
>;

The type is wrong, the type of cursor can be undefined
@yonatan2703 yonatan2703 requested a review from a team as a code owner December 25, 2024 09:49
Copy link

vercel bot commented Dec 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 25, 2024 9:59am

Copy link

vercel bot commented Dec 25, 2024

@yonatan2703 is attempting to deploy a commit to the trpc Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

pkg-pr-new bot commented Dec 25, 2024

Open in Stackblitz

npm i https://pkg.pr.new/trpc/trpc/@trpc/client@6334
npm i https://pkg.pr.new/trpc/trpc/@trpc/next@6334
npm i https://pkg.pr.new/trpc/trpc/@trpc/server@6334
npm i https://pkg.pr.new/trpc/trpc/@trpc/react-query@6334

commit: a1f3489

Copy link
Member

@KATT KATT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a failing test so we don't break this in the future

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.

2 participants