Sharing the app type from my hono api to my client in a monorepo
I'm trying to share types between my Hono API and Svelte app. Currently doing this:
Importing directly from another app like this feels off. What's a better way to share types in a Turborepo setup? Thanks!
8 Replies
thanks friend
i didnt look into what you meant at first but I think you misunderstood my question
the issue is that its an anti-pattern to import between apps in turborepo (and monorepos in general, I think)
so i was basically wondering if theres maybe a way to like generate the type to a package, instead of the export type AppRouter = typeof app;
(cuz it would also be an anti pattern to import the type from the app to the package)
I think if you are just getting the types, it's all good but if you want you can create a package with all your hono routes and then use it in your frontend and backend.
@Aditya Mathur Hey, can you please elaborate for a guy like me who doesn't have much experience setting up all the TS infra...
Right now i have an npm monorepo with client/server folders. I export my Hono app's type like this:
Then i import it on my client like this:
But what i get is that types are not properly inferred on the client:
However, on the server folder types are inferred properly:
Sorry screenshots are messed up but i guess u get the point...
Ok seems that the client can't infer types from Prisma since when i am doing the following it works..
Shouldn't prisma generate auto gen these types for you tho?
so is your issue resolved or are you still having trouble with this setup?
I've finally fixed the issue, it was related to tsconfig in my monorepo, prisma had nothing to do with it...
I had to enable composite: true in the server subrepo and add path reference in the client pointing to tsconfig in the server. Now it is working as expected 🙂
Thank you