When your codebase is being modified at 500 PRs per day by AI agents, the type system becomes load-bearing infrastructure. A type error in a shared interface doesn't break one PR — it blocks a queue. We've invested heavily in type safety patterns that give agents strong guardrails and give reviewers fast signal.
The branded type pattern
The single most impactful pattern we've adopted is branded primitive types. Instead of passing raw strings and numbers across API boundaries, every identifier type is branded at the type level. Agents writing code can't accidentally swap a UserId for an OrgId — the compiler catches it before CI runs.
// Branded types — zero runtime cost, maximum type safety
type UserId = string & { readonly __brand: "UserId" };
type OrgId = string & { readonly __brand: "OrgId" };
function getUser(id: UserId): Promise<User> { ... }
// This fails at compile time — not at runtime
const orgId = "org_123" as OrgId;
getUser(orgId); // TS2345: Argument of type 'OrgId' is not assignable to parameter of type 'UserId'What the numbers showed
After enforcing branded types across core domain objects, the rate of 'wrong-id-type' bugs in AI-generated code dropped to near zero. More importantly, agents started producing code that passed type-check on the first attempt more often — because the type errors are precise enough for the LLM to self-correct before submitting.