vishalbalaji / trpc-svelte-query-adapter

A simple adapter to use `@tanstack/svelte-query` with trpc, similar to `@trpc/react-query`.
71 stars 6 forks source link

Incorrect data types for createInfiniteQuery #25

Closed CoopTRUE closed 6 months ago

CoopTRUE commented 6 months ago

createInfiniteQuery has the incorrect type for data

For example

// route.ts
router({
  infinite: protectedProcedure
    .use(logger)
    .input(
      z.object({
        cursor: z.number(),
      })
    )
    .query(async ({ input, ctx }) => {
      console.log(input)
      const { cursor } = input
      const posts = await db.query.clubPosts.findMany({
        limit: limit + 1,
        offset: cursor,
        ...
        orderBy: (post, { desc }) => [desc(post.createdAt)],
      })

      let nextCursor: number | null = null
      if (posts.length > limit) {
        posts.pop()
        nextCursor = cursor + limit
      }
      return { posts, nextCursor }
    }),
})
// page.svelte
  const feed = trpc($page).explore.infinite.createInfiniteQuery(
    {},
    {
      initialPageParam: 0,
      getNextPageParam: ({ nextCursor }) => nextCursor,
    }
  )

$feed.data incorrectly shows the raw query return type, rather than pageParams and pages

image image

This can be fixed by wrapping InfiniteData on TData in the d.ts

image
CoopTRUE commented 6 months ago

Just realized this was fixed in a recent branch https://github.com/vishalbalaji/trpc-svelte-query-adapter/tree/streamed-queries

Please pull asap

vishalbalaji commented 6 months ago

@CoopTRUE This has been merged and should be fixed in v2.2.3. Thanks for raising the issue!