Hey, devs! I've got a question for all TS folks around. How do you handle sharing common types/interfaces/enums across multiple TypeScript projects? Do you publish them to private NPM package, include into a project as a git sub-module or something else? I'm really curious to see what other options we have nowadays. Please, share your thoughts on this... Thanks you all in advance!
Have a great weekend meanwhile! Cheers!
We looked into a few approaches a while back:
ts
code into sourceI believe we could of went a number of other routes, but didn't look into them at the time, or don't remember them.
We eventually went with the git submodule route, but found it somewhat annoying to deal with versioning, and updates. As updating required a few manual commands every time to build, and push the code back to github. Handling versioning also became annoying as it was very easy to introduce a breaking change. We probably could of did things better at the time but didn't have time to look into it much more.
After a while we started changing to a monorepo approach, which I recommend for full-stack TS projects, as you can leverage typescript's
paths
+ webpack to build what you want and keep everything versioned the same. (you must have a build step, otherwise the paths approach doesn't work)I'm currently using angular+nestjs and some nrwl nx-cli packages to be able to build my front-end and back-end using the angular-cli while sharing some common code using typescript
paths
. I could use angular libs, but I'd consider it overkill for sharing plain types.If I could go back and do it all again, I'd probably go the npm module route if I could pay, and the parameters of the shared code are well defined. Otherwise I would of went with the mono-repo approach if allowable, as I would be able to remove most of the overhead with sharing code, and versioning.