Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do we keep our typescript types sync between frontend and backend (React and node)

I a using React as my frontend and Nodejs as my backend. Many cases I find myself writing the same typescript definition for my server side response and frontend. Is there a way to share the typescript definition between the server and client

interface DadJokes {
  id:string;
  joke: string;
}

When you have big project and you change something on the server side types, sometimes it creates issues when you forget to change it on the client or you make a typo

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

  1. Using TypeScript’s tsc compiler you can generate declarations files for your shared types, which can then be included in both your frontend and backend projects. This can be a good option if you want to keep your shared types in a separate package or library.
  2. Using git submodules you can include a git repository as a subdirectory of another repository.
  3. Using bit.dev you can share code components, including TypeScript types.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading