How should I handle differences in frontend TS types vs database schema?
For example, lets say in my SQLite database I have a
Posts p
table with the columns post_id, (fk) user_id, content
. Assume other tables exist.
But then in my UI I have a TS type Post
that looks like
This is for a personal practice application and I am not using an ORM. I just want to get an idea of how I could approach building a full stack application from mostly scratch.
Thanks.2 Replies
If you're looking for a way to define a common set of rules adapting DB types to the frontend, e.g. stuff like removing ids or converting to camelCase, key mapping in mapped types is your best bet:
https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#key-remapping-via-as
Documentation - Mapped Types
Generating types by re-using an existing type.
Thanks