sweatpants
sweatpants
Explore posts from servers
DTDrizzle Team
Created by sweatpants on 9/21/2024 in #help
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 is static and doesn't update with args but I'm not sure how to go about this better.
1 replies