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
- Triggers on push/PR to specified branches
- Checks out your code from the repository
- Installs Node.js (version 18 in this example)
- Installs dependencies using
npm ci(faster, more reliable thannpm install) - 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.