Can't get the RPC typing
Hey ! Hope you're doing well, I have an issue with the RPC types, how can I manage to get the client types ?
6 Replies
couple things
if you're using rpc, it's recommended that you chain your handlers + middleware
otherwise the inference breaks
also, your i was wrong. it could be simplified though to improve typing performance
each time you do
hcWithType
implementation isn't generic, which will probably cause you some issuestypeof
, the TS server in vs code has to evaluate the type
it's best to do it once + shareThanks for your feedback !
I've updated my code to looks like this now :
And its working !!🚀
I understand my issue, but that's a bit strange behavior to work with... Thanks a lot for your time !
let's gooooooo
happy to help!
using
Parameters<typeof hc>
is kind of an expensive alternative to just importing the option type from hono/client
. what motivates that design, if you don't mind me asking?
as far as "strange behavior", do you mean the chaining? it makes sense if you take a look at the typing. tl;dr - unlike something like trpc, which creates types from the handlers you instantiate, hono rpc takes the merged type output of your app
and your app instance is only aware of what you've chained to it
that's probably the biggest dealbreaker w hono rpc: it doesn't work if you really want a direct code link between the client + the handler
this is also why the cmd+click
isn't workingNo problem, I just pasted what's in the docs https://hono.dev/docs/guides/rpc#compile-your-code-before-using-it-recommended
Do you have a better option ?
RPC - Hono
Web framework built on Web Standards for Cloudflare Workers, Fastly Compute, Deno, Bun, Vercel, Node.js, and others. Fast, but not only fast.
I see
Thanks for your explanation, chaining was my issue
interesting. seems kind of extra. i would do what i shared above: