top | item 46437875

(no title)

supermdguy | 2 months ago

How do you guys share types between your frontend and backend? I've looked into tRPC, but don't like having to use their RPC system.

discuss

order

david422|2 months ago

I do it naively. Maintain the backend and frontend separately. Roll out each change in a backwards compatible manner.

jim201|2 months ago

I used to dread this approach (it’s part of why I like Typescript monorepos now), but LLMs are fantastic at translating most basic types/shapes between languages. Much less tedious to do this than several years ago.

Of course, it’s still a pretty rough and dirty way to do it. But it works for small/demo projects.

Etheryte|2 months ago

So in short you don't share types. Manually writing them for both is easy, but also tedious and error prone.

esafak|2 months ago

I have a library translate the backend types into Typescript. What language do you use on the back?

supermdguy|2 months ago

Typescript, using Zod with Express for parameter validation.

shepherdjerred|2 months ago

Typespec is up and coming. Otherwise there are plenty of options like OpenAPI

programmarchy|2 months ago

FastAPI -> OpenAPI -> openapi-typescript

denysvitali|2 months ago

protobuf?

piva00|2 months ago

Protobuf is decent enough, I've used Avro and Thrift before (way way before protobuf came to be), and the dev experience of protobuf has been the best so far.

It's definitely not amazing, code generation in general will always have its quirks, but protobuf has some decent guardrails to keep the protocol backwards-forwards compatible (which was painful with Avro without tooling for enforcement), it can be used with JSON as a transport for marshaling if needed/wanted, and is mature enough to have a decent ecosystem of libraries around.

Not that I absolutely love it but it gets the job done.