HonoH
Hono4mo ago
Eternal

How to get strict inference with RPC

Here's an example I found online
https://x.com/honojs/status/1953608853654057157

In this example, the RPC infers the response as a "string" rather than the literal Hi!. I somewhat got around this by adding as const at the end of { message: "Hi!"} so it looked like { message: "Hi!"} as const but then I couldn't assign variables to the response of that API call because the API calls response is infered as readonly

I fixed that by doing { message: "Hi!" as const} but is that the "proper" way to achieve strict inference? And why isn't there an example in the docs about this?
Hono (@honojs)
Hono v4.9 is out!

`parseResponse` can parse Response from hc with type-safety

https://t.co/IDfP4IfLt8

X

8/8/25, 12:07 AM

Was this page helpful?