Sub topic 12
Verifying the Fix and Keeping It Fixed
Assume you are comfortable with TypeScript, tsconfig.json, npm, and the tsc command. This chapter shows how to prove that a type-checking change helped and how to stop the problem from returning.
Establish a comparable measurement
A performance change is useful only when you can compare it with a trustworthy baseline. Run the same command before and after the change:
npx tsc --noEmit --extendedDiagnostics > before.txtSave the compiler version, operating system, command, and branch with the measurement. Keep the working tree unchanged except for the performance change. Then repeat the command after the change:
npx tsc --noEmit --extendedDiagnostics > after.txtCompare the important fields:
| Measurement | What it tells you |
|---|---|
| Files | How many source and declaration files are in the program |
| Parse time | Time spent reading and parsing source text |
| Bind time | Time spent connecting declarations and scopes |
| Check time | Time spent resolving and validating types |
| Emit time | Time spent writing JavaScript or declarations |
| Total time | Overall compiler time for this run |
A configuration fix that removes files should reduce Files and often Parse time. A simpler type shape should mainly reduce Check time. A declaration-only change may affect Emit time. Do not call a change successful because total time improved once. Compiler caches, background processes, and machine load can affect one run.
Run each command several times and compare the median. Use the same clean or incremental state for both tests. If you are testing a cold build, remove the old .tsbuildinfo file before both measurements. If you are testing an incremental build, change the same small file before each run.
Verify the intended cause changed
Measure more than the final duration. Check that the suspected cause moved in the expected direction.
For an accidental file or type-package problem, record the program contents:
npx tsc --noEmit --listFilesOnly | grep -v node_modules | sort > files-after.txt
npx tsc --noEmit --explainFiles > explain-after.txtReview the difference against the baseline. A smaller file list is useful only if it still contains every required application file. A missing file can make the compiler faster while making the build incorrect.
For a type-checking problem, generate another trace:
rm -rf trace-after
npx tsc --noEmit --generateTrace trace-after
npx @typescript/analyze-trace trace-afterThe same hot spot should take less time, or it should disappear. If the trace points to a different expensive type, the original fix may have moved the cost rather than removed it.
Test all build modes
A TypeScript project can have different performance characteristics in different workflows.
- Test a cold full check for continuous integration.
- Test an incremental rebuild after a small source change.
- Test declaration emit if the project publishes types.
- Test
tsc --buildif the repository uses project references. - Test the editor if users reported completion or navigation delays.
For an editor-only problem, collect a tsserver log while reproducing the delay. A fast command-line check does not prove that the language service is fast. The editor may load a different configuration, include another project, or perform expensive completion requests.
Prevent regressions
Turn the useful measurements into a small performance check. For example, a continuous integration job can run tsc --noEmit --extendedDiagnostics, save the output, and compare it with a reviewed baseline. Use a threshold rather than an exact time because shared runners vary.
Track structural signals as well:
- maximum file count
- maximum check time
- maximum total time
- maximum declaration-file count
- required project-reference boundaries
- presence of
incrementalorskipLibCheckwhen those settings are intentional
A threshold should trigger investigation, not automatically reject every build. First confirm that the runner, TypeScript version, dependency lockfile, and build mode match the baseline.
The following workflow keeps the diagnosis reproducible:
Exercise
Exercise
A change reduces total tsc time, but the file count and check time remain the same. What should you investigate next?
Show answer
Inspect parse and emit times, then confirm that the tested command and build mode match the reported slowdown. The change may affect output generation or only one part of the workflow.