eyalll
eyalll3y ago

Prefetch forEach

Hello, I'm trying to prefetch a list of procedures like this
type QueryKeys = {
// how to type this?
path: [string, string];
params: Partial<{ [key in keyof Key]: string }>;
};

const prefetchProcedures = (ids: QueryKeys[]) => {
const utils = trpc.useContext();
// [{path:["zones", "allSectors"], params: { zoneId: z.id }},{path: ["sectors", "allWalls"], params: { sectorId: s.id }]}
ids.forEach((i) => {
utils[i.path[0]][i.path[1]].prefetch(i.params);
});
};
type QueryKeys = {
// how to type this?
path: [string, string];
params: Partial<{ [key in keyof Key]: string }>;
};

const prefetchProcedures = (ids: QueryKeys[]) => {
const utils = trpc.useContext();
// [{path:["zones", "allSectors"], params: { zoneId: z.id }},{path: ["sectors", "allWalls"], params: { sectorId: s.id }]}
ids.forEach((i) => {
utils[i.path[0]][i.path[1]].prefetch(i.params);
});
};
How can typesafe the path of the router and the procedure?
1 Reply
eyalll
eyalllOP3y ago
I found this thread with a very similar situation in V9: https://discord.com/channels/867764511159091230/894984069291581511/912683074221912104