Back to Rules

🧠 Claude Rule — TypeScript Quality & Maintainability at Scale

OfficialPopular
ClaudeTypeScript
claudetypescripttype-safetyreactmaintainabilityfrontendbest-practices

You are a senior TypeScript engineer using Claude to enforce type safety, consistency, and long-term maintainability across modern full-stack apps.

🧩 Design Everything with Strong Types

  • Treat the type system as your first defense layer
  • Replace any with meaningful unions or generics
  • Use discriminated unions to prevent runtime ambiguity

Reference: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html

🧱 Structure Code for Clarity

  • Organize by feature domains, not file types
  • Keep your public API clean and limit surface area exports
  • Maintain strict boundaries between client/server code

Reference: https://turbo.build/repo/docs/core-concepts/monorepos

🧬 Model Data as Contracts

  • Define request/response types explicitly
  • Keep API schemas and models versioned
  • Ensure shared data types live in a single source of truth

Reference: https://www.typescriptlang.org/docs/

👁️ Predictable Error Handling

  • Represent recoverable failures as typed responses
  • Fail fast with structured error shapes
  • Let Claude review all thrown errors for consistency patterns
  • Unpredictable errors lead to unpredictable product behavior

✨ React + JSX Type Integration

  • Use JSX element types for safe component interfaces
  • Keep props well-typed — enforce mandatory fields early
  • Prefer composition over prop overload

Reference: https://react.dev/learn/typescript

🚧 Safer Refactoring with Claude

  • Ask Claude to analyze type flow before renaming or deleting code
  • Replace legacy function signatures incrementally
  • Maintain backward compatibility through adapters during migrations
  • Claude can prevent accidental breakage in large codebases

📦 Package & Module Health

  • Avoid deep import paths — they break easily
  • Keep dependency lists minimal and audited
  • Prefer stable @types packages over inline hacks

Reference: https://docs.npmjs.com/about-audits

🔍 Confidence Through Tooling

  • Use ESLint + TypeScript rules to catch consistency issues
  • Include automated checks for unused types and dead code
  • Pair Claude analysis with CI warnings for better developer coaching

Reference: https://typescript-eslint.io/

🌍 Documentation for Future You

  • Describe complex type constructs briefly above usage
  • Auto-generate contract docs for API consumers
  • Encourage visibility: types should explain themselves

🔑 TypeScript Engineering Values

  • The type system is a design tool, not a patch
  • Types prevent bugs humans can't see
  • Refactor with intention and visibility
  • Claude is your type auditor — request validations often
View Tool Page