We have a huge TS monorepo, and we use merge queue in CI environment for merging PRs into it.
The typecheck
job is the bottleneck of the merge queue CI by a large margin, taking 15 minutes.
The typecheck job runs yarn tsc -p
. From what I observe in telemetry, tsc
by default analyzes the whole codebase and only once done, reports any errors. So regardless if typecheck is ✅ or ❌, it takes constant time of 15 minutes.
❓Is it possible to make tsc
throw an error and exit immediately on a first error?
In scope of CI / merge queue, once there’s any error, I want the typecheck job to exit, even if possibly there might be more errors; it’s a fine trade-off: by exiting early, it won’t uselessly block all the PRs behind itself, which will improve merge queue throughput. And the person whose PR was rejected would be asked to rebase their PR and check for all errors. This will put some extra burden on the person whose PR was rejected, but it’s fine.
Note: I’m aware of “project references”, we’re working on this, but it’s something far away for now due to the scale of migration necessary. See a comment on one of the responses below.
Have you looked into using project references? Provided you cache the emitted declarations, it should speed up your build process significantly. Personally, I also use it to type-check different parts of my code base (production code, tests, configs, …) with different settings (in particular: different globals).
Anyway, once you use project references¹ together with the new build mode (tsc --build
), in TypeScript < 5.6, tsc will automatically abort after the first project with an error. In the recently released TypeScript 5.6 you need to run tsc
with --stopOnBuildErrors
.
¹) Maybe this even works with a single project, haven’t tested that, though I suspect tsc
will always finish the current project and only stop afterwards.
2