Passing types along from Hono to Next
We are exploring using Hono as a BFF for our next.js app, which works well in our monorepo, however the types generated on the Hono server are not being passed over the wire to next.js. Can anyone point me in the right direction of what to explore.
hono server which has data typed correctly.
function to fetch the data
consuming the data in next.js with the data coming as untyped (Property 'data' does not exist on type 'unknown'.)
3 Replies
that's just how generics/typescript work
you could try using the hono RPC with a custom fetch fn
if that's the path you take, be sure to use the generated types rather than
export type AppType = typeof app
;
you can find more info on type generation in historic threads/chats on this server
there are some other options, but they get kind of sketchy type-wise
another solution would be to add a parser to your fetch fn. then the expected response type would come from the parsing/validation schema
that's arguably more type-safe, but has worse dx. of course you could always combine the two approachesThanks, I will investigate
Another nice option is to use Orval to generate client code (and types) based on an openapi schema
Assuming you got a fully typed openapi schema