I would like to share TS classes or interfaces between a React + TS frontend and node + TS backend. The problem is that TS types are stripped away in compile time, so I cannot use them when I want to convert a class instance into a JSON.
I was wondering if there are any solutions with which I could describe my object in a static file, generate the TS classes, and use this file for data hydration and dehydration as well. Some properties are moment.js objects and Decimal.js objects. I am looking for a solution where the conversion can be done based on the static descriptor, I don't need to write it for every property manually.
The dehydrated format is used in HTTP request plus it's stored in the DB (Firebase Firestore) and accessed directly by the frontend for reading.