Skip to article content
FrontendXLesson 04 / 16

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.

intermediate · about 25 minutes · 4 exercises

  • Predict
  • Implement
  • Debug
  • Test

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.

snippet.yaml
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.

  1. Exercise 1Predict

    esbuild-wasm transpiles a TypeScript file with a type error. Does it report the type error?

    Choose the best answer
  2. Exercise 2Implement

    Add a type-check job that runs the project check without emitting files.

    starter.yaml
    jobs:
      typecheck:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v4
    

    Reveal the reference answer
    reference.yaml
    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

    Authored 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.

  3. Exercise 3Debug

    This type-check step writes output files and can leave stale artifacts. Fix the command.

    starter.yaml
          - run: npx tsc
    

    Reveal the reference answer
    reference.yaml
          - run: npx tsc --noEmit

    Authored 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.

  4. Exercise 4Test

    Write a function strictEnabled(tsconfig) that returns true only when compilerOptions.strict is true.

    starter.javascript
    function strictEnabled(tsconfig) {
      // return true or false
    }

    Reveal the reference answer
    reference.javascript
    function 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

Related resources

#

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.

© 2026 FrontendX. All rights reserved.