Packaging Up My Types

Hall 1891 typewriter ad

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.

One response to “Packaging Up My Types”

  1. When there are multiple sources of truth for anything, I can’t really think about anything else. What happens if they get out of sync? Will the world end?
    Keep fighting the good fight.

Leave a Reply

Discover more from JacobSewell.dev

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

Continue reading