Risatoga
Risatoga
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Risatoga on 12/17/2023 in #questions
Inference vs type definition
No description
9 replies
TTCTheo's Typesafe Cult
Created by Risatoga on 12/14/2023 in #questions
I MUST BE DOING SOMETHING WRONG Prismadb + Typescript
I MUST BE DOING SOMETHING WRONG Prismadb + Typescript I have been "playing" with typescript this week, and somehow ended up almost migrating my whole side project to ts. The project is a quite complicated directory, so having types and better intellisense actually feels super nice. Not sure how this will evolve but, so far, the experience pretty good. BUT... When it comes to user input-output, I must be doing something wrong. The usual steps for a user interaction (like a form for creating a post) with the database is like this (together with the data tweaking): Display a form: Create a schema with Zod to validate it. Get the post data from the user, create a type of the data sent to the endpoint so you can type the body of que request on the backend. Call the fetch function with that data. You need a type here, that is not necesarily the "db" out of the box type as given by Prisma! (for example, there are not id or created_at fields, or the data is not exactly in the same format). Get the data in the endpoint. Apply the data type you just created in the front end so you "know what you are receiving" in the body. Probably you will need to "enrich" the data (for example, you may want to augment the received data with a related document embeded) --> You need to augment the received data type -> another type. Perform the necessary transformations to the data. Make sure your data meets the requirements of the db for the mutate operation... Another type? In general, I feel like I am overusing types, and that there must be a better workflow for front end - backend interactions (without using trpc - I don't want to have soo many tools, I am just learning!). So...my questions: A. How is your workflow for managing types in io flows like this? B. What are some resources that I can read that help to simplify my ts - prisma interactions? C. Any general advice would be super welcome. THANK YOU!!!
2 replies