Type-Check Gates
Take one task-board application from local tests to a real delivery pipeline: continuous integration fundamentals, push and pull-request quality gates, lint, type-check, unit, component and end-to-end gates, dependency caching, matrix builds, artifacts and checksums, secrets and supply-chain security, release promotion, staging and production, rollback and observability.
What you will be able to do
#- Explain why transpiling is not type-checking.
- Run a type-check gate without emitting files.
- Describe what a type-check gate does and does not prove.
Overview
#Types are erased, not checked, at run time
TypeScript types exist only at compile time. A transpiler such as esbuild or esbuild-wasm strips the annotations and emits JavaScript without checking them. That is why a file can transpile successfully and still contain type errors. The type checker is a separate program, tsc, and it must run as its own gate.
jobs:
typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: corepack enable && pnpm install --frozen-lockfile
- run: pnpm check-types
Check without emitting
Run tsc --noEmit so the gate only reports errors and writes no output files. A check that emits files can leave stale artifacts on the runner and mask whether the check actually passed.
Project references and incremental builds
Large repositories split types across tsconfig project references. The check must build the referenced projects in dependency order, or it will report errors for code that has not been compiled yet. An incremental cache keyed by the source hash keeps the gate fast without making it lie.
What the gate does and does not prove
A type-check gate proves that the code satisfies the declared types. It does not prove the types describe the requirements correctly. A function typed to return a number can still return the wrong number. Types shrink the space of mistakes; they do not eliminate them.
Sandbox boundary
The browser sandbox can transpile a snippet with esbuild-wasm, but transpiling is not type-checking. A sandbox that reports "no errors" after transpiling has checked nothing about types. Only a real tsc run, on a runner or locally, is a type-check gate.
Exercises
#Reference answers and expected output are authored, not executed in this browser. Nothing you type is run, and there is no Run or Pass control on this page.
Exercise 1Predict
esbuild-wasm transpiles a TypeScript file with a type error. Does it report the type error?
Exercise 2Implement
Add a type-check job that runs the project check without emitting files.
starter.yamljobs: typecheck: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4Reveal the reference answer
reference.yamljobs: typecheck: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 20 - run: corepack enable && pnpm install --frozen-lockfile - run: pnpm check-typesAuthored expected output: A typecheck job that installs and runs the project type-check command.
The project check-types script runs tsc in no-emit mode. Keeping it as a separate job makes the failure obvious in the checks list.
Exercise 3Debug
This type-check step writes output files and can leave stale artifacts. Fix the command.
starter.yaml- run: npx tscReveal the reference answer
reference.yaml- run: npx tsc --noEmitAuthored expected output: The step runs tsc --noEmit so no output files are written.
Without --noEmit, tsc emits JavaScript and declarations, which pollutes the workspace and can hide whether checking actually succeeded.
Exercise 4Test
Write a function strictEnabled(tsconfig) that returns true only when compilerOptions.strict is true.
starter.javascriptfunction strictEnabled(tsconfig) { // return true or false }Reveal the reference answer
reference.javascriptfunction strictEnabled(tsconfig) { if (!tsconfig || typeof tsconfig !== 'object') return false; const options = tsconfig.compilerOptions; return Boolean(options) && options.strict === true; }Authored expected output: strictEnabled({ compilerOptions: { strict: true } }) is true; a config without strict is false.
Strict mode is the difference between a type check that catches null and undefined mistakes and one that ignores them.
Common misconceptions
#- If the build succeeds, the types are correct.
- esbuild checks types.
- A type check proves the requirements are correct.
Follow-up practice
#- cicd-05-unit-test-gates
Your progress
#Answers, drafts and completion marks are stored only in this browser. Nothing is sent to a server and no account is used.
Verification: authored. Answers and outputs on this page are authored reference material, not executed results.