In our development process, we utilize Java for backend operations and TypeScript for frontend tasks, each residing in its own repository.
Lately, I've made a shift in the way we handle data exchange between server and client. Instead of sending individual properties like userName and age to the client, we now transmit "RestObjects" (such as UIRestUser) that provide more comprehensive information based on Java classes. These Java "RestClasses" are serialized to JSON and then parsed into objects by our JavaScript/TypeScript code. However, I'm concerned about potential gaps between our TypeScript and Java implementations. Currently, we create parallel interfaces/types in TypeScript to address this issue.
My goal is to define the source type just once. One idea I have is to automatically generate a JSON object representing the types `{userName: string, age: number}` or an actual object `{userName: "Doron", age: 32}` upon each Java commit. This generated JSON could help TypeScript infer the types accurately, possibly through the use of a commit hook or similar mechanism.
Many TypeScript users work with diverse languages on the server side. What strategies and tools can be employed to maintain alignment between types? I welcome any advice or recommendations regarding implementation details and useful tools/libraries for this purpose.