Why I think TypeScript’s value is organizational

An aerial view of downtown Auckland's skyscrapers, port and harbor, with an island in the distance

TypeScript is usually sold on catching bugs, and it does catch some. But I think that undersells it. The value I have seen over a decade of front-end work is organizational. Types are the cheapest way a team has to agree on what things are, and to keep that agreement from decaying as people come and go.

Types as a contract between people

A type at the boundary of a module is a sentence written by one engineer and read by every engineer who touches that module afterwards. It says what goes in, what comes out, and what is optional, and unlike a comment it cannot drift from the truth without the build noticing. On a team of three, everyone can hold that in their heads. On a team of thirty across three time zones, the types are the only version of the agreement that is always current.

This is why I think the places to be strict are the seams. The shape of an API response, the props of a shared component, the events a module emits. Inside a function, a few loose types cost little. At a seam, a loose type is an undocumented agreement, and those are what break at the worst time.

What it does for a distributed team

The hardest part of working across continents is that the person who knows the answer is asleep. A well-typed codebase answers more questions on its own. An engineer in one region can change a shared component and know, before anyone wakes up, which callers they affected. I have come to believe this is worth more than the bug catching, and the bug catching is good.

It also changes onboarding. A new engineer reading well-typed code is reading a map. A new engineer reading untyped code is reading a mystery, and asking the people who are busiest.

The honest cost

TypeScript slows the first week of a prototype and can make a small team feel bureaucratic, especially when someone insists on perfect types for code that will be thrown away. Generics can become a hobby. And a codebase with types everywhere but any at every seam has paid the cost and got none of the value.

Where I would do it differently

A throwaway prototype, a script, or a team of two sharing a room gets little from strict types, and I would not argue for them there. The case grows with the number of people, the number of time zones, and the expected life of the code. For a ten-year product worked on by people who have never met, I think the types are the organization, written down.

Where I am less sure is how AI coding tools change this. They produce types readily, which is good, and they also produce confident wrong ones, which a reviewer has to catch. So far I think it makes the discipline at the seams matter more, not less.

Photo source: https://photos.robertstowe.com/new-zealand