© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago
sweatpants

Returned type inference when using tanstack query

I have a hook
type GetSetGroupsArgs = Parameters<typeof db.query.setGroup.findMany>[0];
export const useSetGroups = (args?: GetSetGroupsArgs) => {
  return useQuery({
    queryKey: ['setGroups', args],
    queryFn: () => db.query.setGroup.findMany(args),
  });
};
type GetSetGroupsArgs = Parameters<typeof db.query.setGroup.findMany>[0];
export const useSetGroups = (args?: GetSetGroupsArgs) => {
  return useQuery({
    queryKey: ['setGroups', args],
    queryFn: () => db.query.setGroup.findMany(args),
  });
};

which works great but the type inference breaks in situations that you might change the result type.

  const { data, error, status } = useSetGroups({
    where: eq(setGroup.workoutId, id),
    with: { sets: { with: { exercise: true } } },
  });
  const { data, error, status } = useSetGroups({
    where: eq(setGroup.workoutId, id),
    with: { sets: { with: { exercise: true } } },
  });


In the case above the data incorrectly doesn't have set with exercises. Which makes sense because the
GetSetGroupsArgs
GetSetGroupsArgs
is static and doesn't update with args but I'm not sure how to go about this better.
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Invalid type inference when using helpers
Drizzle TeamDTDrizzle Team / help
14mo ago
withPagination type inference
Drizzle TeamDTDrizzle Team / help
2y ago
json column type mismatch when using db.query
Drizzle TeamDTDrizzle Team / help
3y ago
No type inference when specifying a reference.
Drizzle TeamDTDrizzle Team / help
2y ago