Typescript Foundations / Typescript Tooling

Type checking inbuild pipelines

In a real-world TypeScript project, type checking ensures your code follows the rules of the type system. While TypeScript can transpile code even with type errors, it’s essential in CI/CD pipelines or builds to block bad code.


🧠 What is Type Checking?

TypeScript has two roles:

  • Transpiling (.ts → .js)

  • Type Checking (ensuring correct types)

You can disable transpile-only mode to force type checking in build pipelines.


🏗️ Type Checking in Build Scripts

Use tsc --noEmit to only perform type checks without outputting .js files:

tsc --noEmit

You can add this to your package.json:

"scripts": {
  "type-check": "tsc --noEmit"
}

This will fail the build if there are type errors — useful in CI.


⚙️ Type Checking with Build Tools

📦 Webpack (with ts-loader)

Enable strict type checking with ts-loader:

// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\\.ts$/,
        use: {
          loader: 'ts-loader',
          options: {
            transpileOnly: false // Enables full type checking
          }
        },
        exclude: /node_modules/
      }
    ]
  }
};

⚡ Vite + TypeScript

Vite uses esbuild by default (which is fast but skips type checking). Add tsc --noEmit manually:

"scripts": {
  "check": "tsc --noEmit"
}

Then in CI:

npm run check

🔍 ESLint with Type Checking

Enable type-aware linting by pointing to your tsconfig.json:

"parserOptions": {
  "project": "./tsconfig.json"
}

But this is heavier, so use it only when necessary.


🧪 Add to CI/CD (GitHub Actions Example)

- name: Run TypeScript type check
  run: npm run type-check

🧩 Tools That Support Type Checking

Tool

Type Checking Support

Notes

tsc

✅ Yes

Use --noEmit for checking only

ts-loader

✅ Yes (if enabled)

Set transpileOnly: false

babel

❌ No

Babel strips types, doesn't check

vite

❌ No (by default)

Add tsc --noEmit manually

esbuild

❌ No

Use tsc separately


📌 Summary

  • ✅ Use tsc --noEmit to type check without emitting files.

  • ✅ Add it to your build script or CI pipeline.

  • 🛠 Configure ts-loader or vite accordingly if using bundlers.

  • 🧠 Type checking helps you fail fast and ensure code safety before shipping.