My team is responsible for development on two different apps within the overarching platform, and we’ve got that code in four different git repositories (two for the frontend, two for the APIs). We’re using Typescript everywhere, which means we do a lot of declaring interfaces, enums, types… and some of those are repeated. It’s been on my wish list for a while to combine the types that exist in more than one repo into a package, and getting to a proof of concept turned out to be easier than I expected.
Right now what I have is a very simple repo with a package.json and an index.d.ts that exports an enum. We’re using an internal registry for packages in the company namespace, so when I npm publish it goes there instead of the global npm registry. Once I’d done that I was able to to install that package in our other repos, delete the now-redundant type, and add the path to the new package in node_modules to typeRoots in tsconfig.json.
This part was significantly less difficult than compiling the list of types that exist in more than one repo. If there’s interest, I’ll come back to that in more detail as we work on moving redundant types into the types package.

Leave a Reply