Advertisement
Advanced TypeScript, Migrating JavaScript to TypeScript

How do you set up a monorepo migration strategy using TypeScript project references so partially-migrated packages don't block fully-typed ones?

Short answer

Use TypeScript's 'references' field in tsconfig.json to declare explicit build dependencies between packages, allowing fully-migrated packages to be built and strictly type-checked independently and incrementally, while less-migrated packages can retain looser settings in their…

Save TypeScript mock interview
Advertisement
AModel answer
Use TypeScript's 'references' field in tsconfig.json to declare explicit build dependencies between packages, allowing fully-migrated packages to be built and strictly type-checked independently and incrementally, while less-migrated packages can retain looser settings in their own tsconfig without holding back the rest of the monorepo's build pipeline.
// packages/core/tsconfig.json
{
  "compilerOptions": { "composite": true, "strict": true },
  "references": []
}

// packages/app/tsconfig.json
{
  "compilerOptions": { "strict": false },
  "references": [{ "path": "../core" }]
}
Real-world example
Migrating a large monorepo where core shared libraries are fully strict-typed first, while application code catches up gradually.
Likely follow-ups
  • What build performance benefit do project references provide beyond just organizing migration strictness levels?
Related topics