Skip to content

Lesson 9 of 9 · 23m

CI Caching, Reproducible Toolchains, and TypeScript Governance

Design CI caching, version pinning, and upgrade practices so TypeScript feedback is fast, reproducible, and trusted by the whole team.

The final TypeScript boss is not a type operator. It is organizational entropy. One developer uses TypeScript 5.4, CI uses 5.6, the editor bundles 5.7, a package requires NodeNext while tests transpile with isolated modules, and everyone argues from a different reality. Toolchain governance sounds bureaucratic until you have lost a release week to phantom type errors.

Pin the compiler and expose the version

A package manager lockfile is necessary but insufficient if multiple package copies can appear:

npm ls typescript    # or: pnpm why typescript

Ideally there is one version. If there are several, understand which tool uses which. Put the answer in CI output:

node -p "require('typescript/package.json').version"

Editors often ship their own compiler. Teams should know how to select the workspace version; otherwise "works for me" can mean "my editor checked a different compiler."

Cache artifacts by lifecycle, not hope

A reasonable CI setup caches dependency installation separately from build output. Dependencies can often be keyed by lockfile and package manager version. Build outputs need source hashing or conservative invalidation. TypeScript .tsbuildinfo, emitted dist, bundler cache, and test transform cache are not interchangeable artifacts.

dependency cache      key: lockfile + package manager + node version
build cache           key: source graph or commit + compiler version
release verification  clean checkout, no incremental artifacts

If the cache is too broad, CI validates stale reality. If too narrow, every pull request pays cold-start cost. There is no universal answer, only explicit tradeoffs.

Separate verification stages by purpose

tsc --build --clean && tsc --build --verbose
npm run lint && npm test -- --runInBand && attw --pack .

Not every project needs all of this, but every project should know why each stage exists. Typechecking is not bundling. Bundling is not runtime verification. Packaging checks are not lint. Combining them into one opaque npm run ci makes failures hard to triage and harder to teach.

Upgrade TypeScript deliberately

Compiler upgrades can introduce new errors in previously valid code. That is often the compiler becoming more correct, but teams experience it as breakage. Treat upgrades as dependency work with a branch, diagnostics review, and release note reading:

npm install --save-exact typescript@5.6.3 && tsc --noEmit --diagnostics

If the upgrade is large, stage it. Fix strictness errors separately from feature adoption. A pull request that both upgrades the compiler and rewrites application types is impossible to review responsibly.

Governance means written decisions

Document the answers: supported module format, runtime targets, compiler version ownership, declaration compatibility expectations, cache policy, and whether generated files are source. Two paragraphs in the repository beat ten rediscovered Slack arguments. TypeScript is a toolchain, not a language setting.

Field notes

  • transpileOnly paths can hide type errors; use them only where a separate typecheck is guaranteed.
  • A green typecheck in a dirty workspace is weaker evidence than a green typecheck in a clean checkout.
  • Beware global installs in CI images. Local devDependencies are the reproducible source of truth.
  • TypeScript, Node, bundler, test runner, and lint parser versions form one compatibility matrix. Upgrade them as a system.
  • If nobody owns the toolchain, everybody owns a slightly different one.

Was this lesson helpful?

Sign in to rate