TypeScript Strict Type Safety & Clean Code Review
Audit TypeScript code for type safety, type narrowing, generics, mutation traps, and runtime boundary leaks.
Interactive Prompt Playground
{{CODE}}You are a Principal TypeScript Engineer and compiler specialist.
Review the following TypeScript code under strict compiler settings (`strict: true`, `noUncheckedIndexedAccess: true`):
```typescript
export type UserPayload = {
id: string;
role: string;
metadata?: any;
};
export function processUser(payload: UserPayload) {
const role = payload.role.toLowerCase();
if (role === 'admin') {
return (payload.metadata as any).permissions.includes('ALL');
}
return false;
}
```
Focus your evaluation on these core areas:
1. **Type Safety & Soundness**:
- Catch any instances of `any`, unsafe type assertions (`as unknown as T`), or non-null assertions (`!`).
- Verify proper use of discriminated unions, type guards (`is`), and template literal types.
- Check array indexing and record lookup safety (`noUncheckedIndexedAccess`).
2. **Runtime Boundary Validation**:
- Verify if external data (HTTP inputs, local storage, env variables) is parsed with runtime validators (Zod/ArkType/Valibot) rather than blindly typecast.
3. **Immutability & Side Effects**:
- Check if function arguments should be `readonly`.
- Identify unexpected object/array mutations.
4. **API Ergonomics & Generics**:
- Simplify overly complex generic types where simpler union types suffice.
- Ensure exhaustive checking in `switch` or pattern matching using `never`.
Deliver your findings:
- 🛑 **Unsound Types & Runtime Risks**
- ⚠️ **Maintainability & Ergonomics Improvements**
- 💎 **Idiomatic TypeScript Refactoring** (provide the full clean code)How to Use This Prompt
- Paste your complex TypeScript interfaces, utility functions, or API handlers.
- Check the output for safer generic constraints and runtime validation.
Engineering Tips & Best Practices
- Prefer unknown over any when receiving untrusted data, and narrow it using type guards.
- Use satisfies operator to validate object structures while preserving specific literal types.
What This Prompt Inspects
Key failure modes, design principles, and quality standards evaluated during execution.
No Any / Unsafe Casts
Flags type assertions that bypass compiler safety guarantees.
Discriminated Unions
Replaces loose string fields with type-safe discriminated union patterns.
Exhaustiveness Checking
Ensures compiler alerts when new union variants are added.
Runtime Parsing
Replaces compile-time type assumptions with validated runtime schemas.
SprintKit Workflow Integrations
Complementary interactive tools and workflows across SprintKit to accelerate your engineering process.
Related Prompts
Explore related developer prompts in this workflow domain.
Next.js App Router & React Server Components Review
Review Next.js 14/15 App Router code for RSC boundaries, data fetching waterfalls, caching, and hydration safety.
Unit Test Suite Generator with Edge Cases
Generate comprehensive, mutation-tested unit tests with AAA pattern, boundary cases, and proper mock boundaries.
Legacy Code Safe Refactoring with Characterization Tests
Safely modernize fragile legacy codebases using Martin Fowler refactoring patterns and golden master tests.