This GitHub Action helps you iteratively migrate your unstrict TypeScript codebase to a strict one. It does this by comparing the TypeScript error count on your pull request’s HEAD branch vs. the BASE branch and fails the workflow if new errors have been introduced.
By ensuring that your error count never goes up, your team can gradually reduce existing errors over time—eventually reaching a fully strict codebase without sudden disruptions.
- Checkout and run
tscon the HEAD branch (the PR branch). - Extract the number of errors from the compiler output.
- Checkout the BASE branch and run
tscagain. - Compare the two error counts and fail the workflow if the HEAD error count is greater.
This approach enforces a “no new errors” policy, allowing teams to chip away at TypeScript errors and strictness violations without overwhelming developers.
In your repository, create or update a GitHub Actions workflow file (e.g. .github/workflows/compare-tsc-errors.yml) with the following:
name: Compare TSC Errors
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
compare-tsc-errors:
runs-on: ubuntu-latest
steps:
- name: Compare TSC on HEAD vs BASE
uses: thinkdx/ts-stricter@v1- Pull Request Context: This Action is specifically designed for pull_request events because it compares HEAD vs. BASE.
- Node Setup: If you need a different Node version or have a custom install step, place those steps before calling the Action.
- Permissions: Ensure the workflow has sufficient permissions for checking out and reading the repository.
- tsconfig: Make sure your repository has a
tsconfig.jsonthattsccan recognize. - No Additional Errors: If the PR introduces new TypeScript errors, the Action will fail, helping maintain or reduce your overall error count.
- Iterative Strictness: Incrementally refactor your codebase to stricter TypeScript settings without a large one-time lift.
- Prevent Regression: Ensure new pull requests don’t introduce additional errors, keeping your journey to strictness on track.
- Simple Integration: Add a single workflow step that automatically checks and enforces your error budget.
Contributions and feedback are welcome! If you have new ideas or run into issues, please open a GitHub issue or submit a pull request to this repository.
This project is licensed under the MIT License. Feel free to modify and reuse in your own projects.