Share types between front and and backend without trpc...
I'm working on a project using
nextjs
, Hono js
, drizzle
, turborepo
. I don't want to use trpc and would like to enforce types. I want to infer the return type of the fetchMyCollection
to export it and use it in the nextjs app.
I tried to do type myType = ReturnType<typeof fetchAlbum>
but this is only a shallow type. How can properly share the types across the backend and nextjs?
1 Reply
Try using this website. If you paste a JSON object into it, it not only creates interfaces and enums for you, but it also gives you a set of functions to validate against that interface. This might be what you're looking for
Instantly parse JSON in any language | quicktype
Whether you're using C#, Swift, TypeScript, Go, C++ or other languages, quicktype generates models and helper code for quickly and safely reading JSON in your apps. Customize online with advanced options, or download a command-line tool.