-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Description
Proposal: https://expensify.slack.com/archives/C08CZDJFJ77/p1771923976005829
Proposal: Early adoption of tsgo for faster type checking during development
Background
Our codebase uses tsc (TypeScript 5.x) for type checking, invoked via npm run typecheck. Developers run it locally before pushing, CI runs it on every PR, and AI coding agents (Claude Code, Cursor, Copilot) run it after every code change to verify correctness.
Microsoft has been developing a native port of the TypeScript compiler written in Go, known as tsgo (to be released as TypeScript 7). It is available on npm as @typescript/native-preview and promises ~10x faster type checking. The project is still in active development and may not yet be 100% stable, but its authors state that its type checking produces the same errors, locations, and messages as TypeScript 6.0.
tsgo is also stricter than tsc — during our initial integration it caught genuine bugs that tsc silently accepted: duplicate keys in type mappings and missing null checks.
Problem
When a developer or AI agent makes a type-level change, the tsc type check significantly slows down the development iteration loop, which reduces development velocity and discourages running type checks before pushing.
Solution
Adopt tsgo incrementally for development-only type checking in three stages, keeping tsc as the production CI gate until tsgo reaches full stability.
Stage 1: Local npm command
Draft PR: #83228
Add @typescript/native-preview as a dev dependency and configure a dedicated tsconfig.tsgo.json that mirrors the main tsconfig.json (with adjustments for tsgo compatibility, such as removing baseUrl which TypeScript 7 has deprecated). Fix existing bugs detected by tsgo — duplicate keys in type mappings, incorrect field assignment, missing null checks, and incorrect module import paths.
Developers can run npm run typecheck-tsgo locally for a fast type-check pass during development. The existing npm run typecheck (tsc) remains unchanged and continues to be the source of truth.
Expensify App benchmark:
Full check: 116.3s → 15.7s (-86%)
Incremental (no changes): 9.2s → 1.6s (-83%)
Memory usage: 6,428MB → 5,463MB (-15%)
Stage 2: CLAUDE.md integration for AI agents
Add guidance to CLAUDE.md so AI agents prefer npm run typecheck-tsgo for iterative type checking. Agents run type checks after every change — a ~10x speedup directly reduces task completion time and cost. Since tsgo is stricter, code that passes it is likely to also pass tsc.
- For iterative development, prefer
npm run typecheck-tsgo(faster, stricter) thennpm run typecheck.
Stage 3: GitHub Actions integration
Add typecheck-tsgo as a blocking CI check on PRs, alongside existing tsc. Both checks are required — tsc remains necessary before full migration to ensure correct application builds, while tsgo enforces stricter type safety to simplify development and keep main clean. An additional benefit is that once tsgo reaches production readiness, the codebase will already be fully compatible and ready for migration.