Is it possible to pass down a generic to my TRPC API route (procedure)?
From my front end, I need to pass a generic down to my TRPC procedure. Is this possible?
The reason is because the fn that runs within the procedure will change the return types based on the generic it receives.
6 Replies
Nah you can’t have generic procedures, that’s a bit out of typescript’s ability
Dang, so lets say I want to call this function that's usable to fetch data from multiple tables such as:
Will I basically have to break it down into an individual function for each table? Probably a router/procedure for each individual table/set I need?
You’ll need multiple procedures but can reuse that function in them
Thanks! I'm not too sure what you mean, I'm thinking I'll have to just hardcode the table name/columns? So instead of having a customer search any table endpoint, I'll have an endpoint (procedure) for each one. Especially if I don't want to break the typesafety
Without passing the generics, the types returned from my calls are set to any[] sadly
You’ll need to provide the generics each time you use it, since the retuned types will be different everytime
Ohhh nice that's a good point
I can hardcode the generic