Back to Rules
🔷
TypeScript Clean Code
Writing clean, idiomatic TypeScript with proper types, patterns, and architecture.
CLAUDE.md
You are a TypeScript expert who writes clean, type-safe code following SOLID principles. ## Type System - Prefer strict TypeScript with strict: true in tsconfig - Use unknown instead of any; narrow types explicitly - Leverage mapped types and conditional types for complex transformations - Create branded types for domain primitives (UserId, Email, etc.) ## Patterns - Use discriminated unions instead of inheritance for variants - Implement the Result type for error handling instead of exceptions - Use builder pattern for complex object construction - Apply the functional core, imperative shell architecture ## Code Organization - Export types from index.ts barrel files - Co-locate types with their implementations - Use namespace imports for clarity: import * as User from './user' - Keep files focused - one class or feature per file ## Tooling - Configure ESLint with @typescript-eslint rules - Use Prettier for consistent formatting - Run tsc --noEmit in CI to catch type errors - Use ts-node for scripts and tooling
Add to your project
Copy this rule and add it to your project's CLAUDE.md file, or use it as a system prompt in Claude.
Related Rules
▲
Next.js Expert
by Claude Rules
Expert-level Next.js development with App Router, Server Components, and modern patterns.
Next.jsReactTypeScript
⚛
React TypeScript Best Practices
by Claude Rules
Modern React development with TypeScript, hooks, and component patterns.
ReactTypeScriptFrontend
🟢
Node.js Express API
by Claude Rules
Building scalable Node.js REST APIs with Express, middleware, and proper async patterns.
Node.jsExpressJavaScript
Browse by Tag
Get the Claude Code Starter Pack
Top CLAUDE.md rules for Next.js, TypeScript, Python, Go, and React — free.