Skip to content

Add TypeScript type checking to pre-commit or CI #1202

Closed

Description

@mihow

Problem

TypeScript type errors in the frontend can slip through to CI/Netlify builds because there is no local type checking step. The current .pre-commit-config.yaml excludes ui/ entirely (line 1: exclude: "^docs/|/migrations/|ui/"), and we only run prettier formatting checks in CI, not tsc.

This was exposed in PR #1198 where a type mismatch (null added to one interface but not a dependent one) passed local commits and was only caught by the Netlify build.

Proposal

Add tsc --noEmit as a check that runs before code reaches CI. Three approaches, from simplest to fastest:

Option A: pre-commit hook (repo: local)

# .pre-commit-config.yaml
- repo: local
  hooks:
    - id: ui-typecheck
      name: TypeScript type check
      entry: bash -c 'cd ui && npx tsc --noEmit'
      language: system
      files: ^ui/.*\.(ts|tsx)$
      pass_filenames: false
  • Adds ~10s to commits touching TS files
  • Uses files: pattern to bypass the global exclude: ui/ rule
  • pass_filenames: false because tsc --noEmit must check the whole project (type errors can cascade across files)

Option B: Husky + lint-staged

// ui/package.json
"lint-staged": {
  "*.{ts,tsx}": ["bash -c 'tsc --noEmit'"]
}

With Husky managing the git hook from the ui/ directory. This is more standard for JS/TS projects and keeps frontend tooling self-contained, but adds another hook manager alongside pre-commit.

Option C: CI-only check (fastest local workflow)

Add tsc --noEmit as a step in the GitHub Actions / Netlify CI pipeline, separate from the build. Catches errors before deploy without slowing local commits. Downside: errors are caught later in the feedback loop.

Notes

  • tsc --noEmit cannot meaningfully check a subset of files — TypeScript's type system is whole-program, so a change in file A can cause errors in file B through imported types
  • Current tsc --noEmit takes ~10s on this project
  • The existing Netlify build already catches these errors, but the feedback loop is slow (~2-3 min)

Activity

  1. annavik commented on Apr 3, 2026

    @annavik
    Member

    Good idea! Could be nice to separate type checks from the build step.

    I vote fore option C, I'm personally not a big fan of pre-commit hooks, I feel they interrupt my workflow a bit. I like direct feedback in my editor better, together with the more complete CI checks :) But I also don't mind them too much, so I could adjust.

    I opened a PR for the CI part: #1207

  2. mihow commented on Apr 3, 2026

    @mihow
    CollaboratorAuthor

    Thanks for looking at this! I guess I use a variety of editors and not always a full IDE. Lately I have been pushing a few changes with type issues that only get caught when Netlify tries to build the deploy preview, which makes for a long development cycle. If there is a fast check that can be added pre-push that is helpful for reducing build minutes (and energy!) in the GitHub CI actions. But the new CI check you added should help speed that up. I can try to remember to run it manually before pushing too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions