| name | typescript-incremental-check |
| description | Fast TypeScript error detection patterns and best practices for immediate compilation verification. Use immediately after code edits, before proceeding to testing, or when TypeScript errors are discovered late. Run npx tsc --noEmit immediately after edits to catch errors early. |
TypeScript Incremental Check
Overview
Catch TypeScript errors immediately after code edits. Don't wait until end of task to check compilation.
Immediate Verification
Run npx tsc --noEmit immediately after code edits
Critical: Check TypeScript compilation BEFORE proceeding to testing or browser automation.
Workflow:
- Make code edit
- Run
npx tsc --noEmit immediately
- Fix any errors
- Continue with next edit or testing
Workflow Timing:
- After file edits: Run check immediately
- Before browser testing: Run check first
- Before running tests: Run check first
- Before marking complete: Run check to verify
Don't wait until end of task to check compilation - catch errors early.
Run from correct package directory
- Run
npx tsc --noEmit from the correct package directory (e.g. cd backend && npx tsc --noEmit or use --project backend/tsconfig.json from repo root). Do not assume shell CWD from a previous command.
- Do not run tsc until a TypeScript/Next.js project exists (e.g. after create-next-app). Use presence of
tsconfig.json or next.config to decide.
- After a successful tsc in the same turn, do not run it again unless source files were changed in between.
Quick Check Script
Use scripts/check-ts.sh for quick TypeScript compilation check:
./scripts/check-ts.sh
Common Errors to Prevent
See references/common-errors.md for detailed error patterns:
- Syntax errors (extra/missing braces)
- Method name mismatches (check actual method names)
- Type mismatches (verify interface compatibility)
- Import path errors (use relative paths)
Common Error Patterns and Quick Fixes
Syntax Errors
Pattern: Missing/extra braces, parentheses, semicolons
Quick fix: Check for balanced brackets, verify semicolons
if (condition) {
doSomething();
if (condition) {
doSomething();
}
Method Name Mismatches
Pattern: Calling method that doesn't exist or wrong name
Quick fix: Check actual method names in source code
scene.restartGame();
scene.restart();
Type Mismatches
Pattern: Type doesn't match expected interface
Quick fix: Verify interface compatibility, check actual types
const score: number = gameState.score;
const score: number = parseInt(gameState.score);
Import Path Errors
Pattern: Import path doesn't resolve
Quick fix: Use relative paths, check file existence
import { GameState } from '@/types/GameState';
import { GameState } from '../types/GameState';
Strict Mode Handling
When strict mode is enabled:
- Null/undefined checks required
- No implicit any types
- Stricter type checking
Patterns:
if (this.player) {
this.player.update();
}
this.player?.update();
if (value !== null && value !== undefined) {
}
Type Definition Patterns
Test Seam Type Definitions
declare global {
interface Window {
__TEST__?: {
ready: boolean;
sceneKey: string | null;
gameState: () => any;
commands: {
[key: string]: (...args: any[]) => void;
};
};
}
}
Window Extensions
declare global {
interface Window {
game?: Phaser.Game;
}
}
Best Practices
- Use smaller, incremental edits
- Verify compilation after each logical change
- Check method names in source code before using
- Use IDE/linter for real-time error detection if available
- Don't wait until end of task to check compilation
Early Type Checking Workflow
Run type-check immediately after code changes:
edit_file("src/scenes/GameScene.ts", ...)
npx tsc --noEmit
Fix errors before extensive testing:
Re-check after fixes:
npx tsc --noEmit
Export/Import Validation
Validate exports before imports:
grep -r "export.*functionName" src/
grep -r "^export" src/utils.ts
Check import/export consistency:
export function myFunction() { }
import { myFunction } from './utils';
import { myOtherFunction } from './utils';
Use tsc --noEmit for quick validation:
npx tsc --noEmit
Fix before full build:
npx tsc --noEmit
npm run build
npm run build
npm run build
Common Error Patterns
Missing exports:
function myFunction() { }
export function myFunction() { }
Type conflicts (Settings class vs type):
class Settings { }
type Settings = { };
class Settings { }
type SettingsData = { };
Property initialization issues:
class GameScene {
private player: Player;
}
class GameScene {
private player: Player;
constructor() {
this.player = new Player();
}
}
Global type extensions:
declare global {
interface Window {
__TEST__?: {
ready: boolean;
sceneKey: string | null;
};
}
}
Workflow Integration
Immediate Type Checking
After code changes:
edit_file("src/scenes/GameScene.ts", ...)
npx tsc --noEmit
Before Testing
Always check types before testing:
npx tsc --noEmit && agent-browser open http://localhost:3000
npx tsc --noEmit && npm test
Before Completion
Verify types before marking complete:
npx tsc --noEmit
Integration with Other Skills
- typescript-type-safety: Complements with type definition patterns
- pre-implementation-check: Validates types before implementation
- task-verification-workflow: Includes type checking in verification
Resources
scripts/check-ts.sh - Quick TypeScript compilation check script
references/common-errors.md - Syntax errors, method name mismatches, type mismatches