Chapter 1 · Practice 6 of 6
Run the type checker in CI, separate from the build
Why it matters
Many fast tools, including Node's type stripping, esbuild, SWC and most bundlers, remove types without checking them. A project can build and run while full of type errors. The only thing that checks types is the TypeScript compiler (or its language service in your editor).
Add a dedicated step that runs tsc --noEmit (or tsc -b with project references) and fails the pipeline on any error. Run it on every pull request, next to tests and lint. With TypeScript 7 this step is usually short enough that there is no reason to skip it.
Do
- Add a
typecheckscript that runstsc --noEmitand call it in CI - Fail the pipeline on type errors the same way you fail on test errors
Avoid
- Assuming the bundler or
node file.tschecked your types
Example
{
"scripts": {
"typecheck": "tsc --noEmit",
"lint": "eslint .",
"test": "vitest run"
}
}