C.W.K.
Stream
Lesson 09 of 13 · published

Type Checking

~11 min · types, mypy, pyright, tsc

Level 0Apprentice
0 XP0/101 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

The compile-time gate that lint can't do

Type checking is what catches bugs lint cannot — wrong-type arguments, missing fields, unhandled None / null, mismatches between API contracts. It runs at the boundary between 'static analysis' and 'simulated execution' — it walks every code path mentally so you don't have to.

The major checkers

  • Python — mypy: gradual typing, the original. Reads PEP 484 type hints. Strict mode is recommended (--strict).
  • Python — pyright: Microsoft's. Faster, more accurate inference, powers Pylance in VS Code. Often used alongside ruff.
  • TypeScript — tsc: tsc --noEmit just type-checks without producing output. The canonical gate.
  • JavaScript with JSDoc — yes, JSDoc + // @ts-check buys you most of TypeScript's checking without a transpile step.

Type checking in CI

  1. Make it a separate job (parallel with test, lint).
  2. Pin the checker version — type errors change between releases.
  3. Output should be both human-readable and machine-readable when you want annotations on the PR diff.
  4. For Python, run on the same Python version as production.

Code

Parallel type-check jobs (Python + TypeScript)·yaml
  type-check-python:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: astral-sh/setup-uv@v3
      - run: uv sync --all-extras --dev
      - run: uv run mypy src --strict --no-incremental

  type-check-typescript:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: pnpm/action-setup@v4
        with: { version: 9 }
      - uses: actions/setup-node@v4
        with: { node-version: '22', cache: pnpm }
      - run: pnpm install --frozen-lockfile
      - run: pnpm tsc --noEmit

External links

Exercise

Add a strict type-check job to your CI workflow. Run it once locally first to fix any existing errors, then push it. From then on, types are part of the build.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.