Strict TypeScript Type Safety & Soundness Audit
Audit TypeScript code for type safety, type narrowing, generics, mutation traps, and runtime boundary validation.
Enforce strict type safety, eliminate 'any' and unsafe type assertions, implement type narrowing, and validate runtime boundary data.
Execution Workflow Procedure
Ordered steps the coding agent executes when performing this skill.
Identify Unsound Types & Casts
Scan for any, unknown casts (as any, as T), and non-null assertions (!). Replace them with type guards or validated schemas.
Enforce Discriminated Unions & Exhaustiveness
Replace loose string/number status codes with discriminated unions. Implement exhaustive pattern matching using the 'never' type.
Audit Runtime Boundaries
Ensure data coming from external I/O (API calls, local storage, URL params) is parsed with runtime validators (Zod/ArkType) rather than assumed.
Refactor to Immutable Interfaces
Add readonly modifiers to array and object props where functions should not mutate their inputs.
Agent Safety Guardrails & Anti-Hallucination Rules
- DO NOT introduce complex nested conditional types when simple discriminated unions suffice.
- DO NOT use type assertions to bypass compiler errors without verified runtime validation.
Expected Output Format
Evaluation of compiler soundness and runtime safety.
Domain Verification Checks
Example Agent Invocations
Install / Configure This Skill
# Place in .cursorrules or create .cursor/rules/strict-typescript-code-review.mdc # Trigger: Whenever you perform strict typescript type safety & soundness audit --- name: strict-typescript-code-review description: Audit TypeScript code for compiler soundness, type narrowing, discriminated unions, and runtime boundary validation. version: 1.0.0 compatibility: [Cursor, Claude Code, Cline, Roo Code, Antigravity] --- # Strict TypeScript Type Safety & Soundness Audit ## Objective Eliminate `any`, unsafe type assertions, and unvalidated runtime boundaries across TypeScript repositories. ## Workflow 1. **Unsound Type Scan**: Find and replace all `any` and non-null `!` assertions with type guards (`is`) or runtime parsing. 2. **Discriminated Unions**: Convert loose status flags into discriminated union objects with exhaustive `never` checks. 3. **Runtime Boundaries**: Enforce schema parsing on all HTTP and environment inputs using Zod. 4. **Immutability**: Add `readonly` modifiers to function arguments and state models.
Need a quick one-time prompt for chat?
Try the TypeScript Strict Type Safety & Clean Code Review — a lightweight version designed for 1-click copying directly into Claude, ChatGPT, or Cursor chat.
SprintKit Workflow Integrations
Complementary tools and checklists to pair with this agent workflow.
Related Agent Skills
Explore related procedural workflows in this discipline.
Next.js App Router & React Server Components Review
Inspect Next.js App Router code for RSC boundaries, data fetching waterfalls, caching, and hydration safety.
Comprehensive Unit Test Suite Generation (AAA Pattern)
Generate mutation-tested unit tests with Arrange-Act-Assert structure, boundary cases, and proper mock boundaries.
Safe Legacy Code Modernization with Golden Master Tests
Safely modernize fragile legacy codebases using Martin Fowler refactoring patterns and characterization tests.