ragokan
ragokan17mo ago

Dynamic return type

Is there any way to have dynamic return type with tRPC? Simple example: If I provide x: true on body, let me send number, otherwise string. But mainly, I want to use it for select fields on database
Solution:
Is there any way to have dynamic return type with tRPC? Simple example: If I provide x: true on body, let me send number, otherwise string. ...
Jump to solution
5 Replies
Michael Schaufelberger
The return type is automatically inferred depending on what you do in the procedure. Or does your code behave differently?
ragokan
ragokanOP17mo ago
Not asking that actually. I am asking about returning dynamic So, when I do this, it says return type is number | string But I am trying to make it number when I provide x:true
Michael Schaufelberger
ah, so you mean like typescript function overloads?
Martin
Martin17mo ago
FAQ / Troubleshooting | tRPC
Collection of frequently asked questions with ideas on how to troubleshoot & resolve them.
ragokan
ragokanOP17mo ago
okay thank youu