client of type unknown
I am having issues with the type inference of the client when using hono rpc
I've read https://hono.dev/docs/guides/rpc, https://hono.dev/examples/grouping-routes-rpc, and https://github.com/honojs/hono/issues/3148 and have adjusted my code accordingly, but am still getting this issue
please see my hono code: https://github.com/picafe/cs-ia/tree/hono/backend/src/routes and https://github.com/picafe/cs-ia/tree/hono/backend/src/index.ts
client is here: https://github.com/picafe/cs-ia/blob/hono/client/src/lib/client.ts
apologies in advance for my terrible code
feel free to ask for any more details, any help would be very appreciated 🙏
GitHub
'client' is of type 'unknown' when using route · Issue #3148 · ho...
What version of Hono are you using? 4.5.0 What runtime/platform is your app running on? Bun What steps can reproduce the bug? I have a very basic application structure, which I was hoping to be abl...
15 Replies
you should generate the type, esp when using a monorepo
this may also help: https://hono.dev/docs/guides/rpc#compile-your-code-before-using-it-recommended
this probably isn't helping:
const userRoutes: Hono<AppEnv> = new Hono<AppEnv>()
you're overriding the type inferred from your routes with a more-generic type that doesn't know anything about your routes at all
try const userRoutes = new Hono<AppEnv>()
that worked in getting the client to infer types, thank you 🙏
but I did that because of this typeerror

Hm. I’ve never seen that before. Where is that error being thrown? Can you share a screenshot?
Using generated types might solve the issue, or are you doing that now?
it happens in every separated route file on the server

Hm. Seems like a
tsconfig
issue. It might have to do with the composite
setting, or you might need to adjust base path resolutionit could be base path, ill try to figure it out
This might be helpful: https://github.com/microsoft/TypeScript/issues/42873
Idk that explicit type annotation is ever a good solution to this problem. It’s more of a project config issue. There might be some edge cases though
I’d recommend searching this server for monorepo examples. I don’t think there are any official example repos, but the community has definitely shared projects that could be helpful references
What does AppEnv look like? Ive only had that happen when I was trying to control the generics too much
Also, try opening pallette and “restart ts server” and “reload project”. Tsc gets stuck on typing sometimes
i'm using better-auth so I copied the app env from their hono docs:
https://www.better-auth.com/docs/integrations/hono#middleware
Hono Integration | Better Auth
Integrate Better Auth with Hono.

yeaa ive tried a few times but still giving that typeerror
How are you mounting them, do other routes also have an AppEnv applied?
this is what i did initially for all my routes and the base app because all gave the typeerror i mentioned earlier

however with this it works as intended

oh waht... I just came home and now the error is gone...
i didnt even close and repoen my ide
this is interesting
uuhh okay i think everything works now