H
Hono•2w ago
owopi

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
ambergristle
ambergristle•2w ago
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>()
owopi
owopiOP•7d ago
that worked in getting the client to infer types, thank you 🙏
owopi
owopiOP•7d ago
but I did that because of this typeerror
No description
ambergristle
ambergristle•7d ago
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?
owopi
owopiOP•7d ago
The inferred type of 'userRoutes' cannot be named without a reference to '../../../client/node_modules/hono/dist/types/utils/http-status'. This is likely not portable. A type annotation is necessary.ts(2742)
The inferred type of 'userRoutes' cannot be named without a reference to '../../../client/node_modules/hono/dist/types/utils/http-status'. This is likely not portable. A type annotation is necessary.ts(2742)
The inferred type of 'userRoutes' cannot be named without a reference to '../../../client/node_modules/hono/dist/types/hono-base'. This is likely not portable. A type annotation is necessary.ts(2742)
The inferred type of 'userRoutes' cannot be named without a reference to '../../../client/node_modules/hono/dist/types/hono-base'. This is likely not portable. A type annotation is necessary.ts(2742)
it happens in every separated route file on the server
No description
ambergristle
ambergristle•7d ago
Hm. Seems like a tsconfig issue. It might have to do with the composite setting, or you might need to adjust base path resolution
owopi
owopiOP•7d ago
it could be base path, ill try to figure it out
ambergristle
ambergristle•7d ago
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
atoko
atoko•7d ago
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
owopi
owopiOP•7d ago
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.
No description
owopi
owopiOP•7d ago
yeaa ive tried a few times but still giving that typeerror
atoko
atoko•7d ago
How are you mounting them, do other routes also have an AppEnv applied?
owopi
owopiOP•7d ago
this is what i did initially for all my routes and the base app because all gave the typeerror i mentioned earlier
No description
owopi
owopiOP•7d ago
however with this it works as intended
No description
owopi
owopiOP•7d ago
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

Did you find this page helpful?