Course contentsShow
← TypeScript
Lesson 1265 of 1,79629. The Build PipelineFree lesson

Setting Up GitHub Actions for TypeScript

Creating a GitHub Actions workflow that installs dependencies and runs tsc to validate types on every push.

Setting Up GitHub Actions for TypeScript

What you'll learn: How to create a GitHub Actions workflow that automatically installs dependencies and runs TypeScript type-checking on every push to your repository.

Why Automate Type-Checking?

Running tsc --noEmit locally is great, but it's easy to forget. GitHub Actions ensures that every push to your repository gets type-checked automatically, catching type errors before they reach production. Think of it as a safety net that catches you whenever you forget to verify types locally.

Creating Your First Workflow

GitHub Actions workflows live in .github/workflows/ in your repository. Create a file called typecheck.yml:

name: Type Check

on:
  push:
    branches: [ main, develop ]
  pull_request:
    branches: [ main ]

jobs:
  typecheck:
    runs-on: ubuntu-latest
    
    steps:
      - uses: actions/checkout@v3
      
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '18'
      
      - name: Install dependencies
        run: npm ci
      
      - name: Run TypeScript type check
        run: npx tsc --noEmit

What This Workflow Does

  1. Triggers on push/PR to specified branches
  2. Checks out your code from the repository
  3. Installs Node.js (version 18 in this example)
  4. Installs dependencies using npm ci (faster, more reliable than npm install)
  5. Runs type-checking without emitting files

The build fails if tsc finds any type errors, preventing broken code from being merged.

Key Takeaway: GitHub Actions workflows automate TypeScript validation by installing dependencies and running tsc --noEmit on every push, ensuring type safety across your entire team without manual intervention.