Code Review & Quality
Compatible with Cursor, Claude Code, Cline, Roo Code, Antigravity, GitHub Copilot

Strict TypeScript Type Safety & Soundness Audit

Audit TypeScript code for type safety, type narrowing, generics, mutation traps, and runtime boundary validation.

TypeScriptNode.jsClean CodeArchitecture
Skill Objective

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.

1

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.

2

Enforce Discriminated Unions & Exhaustiveness

Replace loose string/number status codes with discriminated unions. Implement exhaustive pattern matching using the 'never' type.

3

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.

4

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.

🛑 Unsound Types: Unsafe type assertions, any types, or unhandled nullables.
💡 Ergonomics & Narrowing: Discriminated unions and generic type improvements.
🛠️ Corrected TypeScript Code: Fully typed, strict TypeScript implementation.

Domain Verification Checks

Zero Any / Casts: Replaces unsafe type bypasses with type guards.
Discriminated Unions: Models domain states with type-safe tag fields.
Runtime Parsing: Enforces Zod validation at system boundaries.

Example Agent Invocations

"Review this TypeScript utility module for unsafe type assertions and generic constraints."
"Refactor this Redux/Zustand state store to use strict discriminated unions."

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.
Complementary Agent Prompt

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.

View Prompt

SprintKit Workflow Integrations

Complementary tools and checklists to pair with this agent workflow.

Related Agent Skills

Explore related procedural workflows in this discipline.

All Skills

Next.js App Router & React Server Components Review

Inspect Next.js App Router code for RSC boundaries, data fetching waterfalls, caching, and hydration safety.

ReactNext.jsTypeScript+2
4 workflow stepsView skill

Comprehensive Unit Test Suite Generation (AAA Pattern)

Generate mutation-tested unit tests with Arrange-Act-Assert structure, boundary cases, and proper mock boundaries.

TestingJUnitVitest+3
3 workflow stepsView skill

Safe Legacy Code Modernization with Golden Master Tests

Safely modernize fragile legacy codebases using Martin Fowler refactoring patterns and characterization tests.

RefactoringClean CodeDesign Patterns+1
4 workflow stepsView skill