logoalt Hacker News

Etherytelast Tuesday at 9:31 PM1 replyview on HN

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


Replies

Arainachlast Tuesday at 9:58 PM

Each layer of your stack should have different types.

Never expose your storage/backend type. Whenever you do, any consumers (your UI, consumers of your API, whatever) will take dependencies on it in ways you will not expect or predict. It makes changes somewhere between miserable and impossible depending on the exact change you want to make.

A UI-specific type means you can refactor the backend, make whatever changes you want, and have it invisible to the UI. When the UI eventually needs to know, you can expose that in a safe way and then update the UI to process it.

show 2 replies