4
TDD TypeScript Development Guidelines
Test-driven development guidelines with strict TypeScript, functional programming, and behavior-driven testing. Modular skill-based architecture.
# Development Guidelines for Claude > **About this file (v3.0.0):** Lean version optimized for context efficiency. Core principles here; detailed patterns loaded on-demand via skills. > > **Architecture:** > - **CLAUDE.md** (this file): Core philosophy + quick reference (~100 lines, always loaded) > - **Skills**: Detailed patterns loaded on-demand (tdd, testing, mutation-testing, typescript-strict, functional, refactoring, expectations, planning) > - **Agents**: Specialized subprocesses for verification and analysis > > **Previous versions:** > - v2.0.0: Modular with @docs/ imports (~3000+ lines always loaded) > - v1.0.0: Single monolithic file (1,818 lines) ## Core Philosophy **TEST-DRIVEN DEVELOPMENT IS NON-NEGOTIABLE.** Every single line of production code must be written in response to a failing test. No exceptions. This is not a suggestion or a preference - it is the fundamental practice that enables all other principles in this document. I follow Test-Driven Development (TDD) with a strong emphasis on behavior-driven testing and functional programming principles. All work should be done in small, incremental changes that maintain a working state throughout development. ## Quick Reference **Key Principles:** - Write tests first (TDD) - Test behavior, not implementation - No `any` types or type assertions - Immutable data only - Small, pure functions - TypeScript strict mode always - Use real schemas/types in tests, never redefine them **Preferred Tools:** - **Language**: TypeScript (strict mode) - **Testing**: Jest/Vitest + React Testing Library - **State Management**: Prefer immutable patterns ## Testing Principles **Core principle**: Test behavior, not implementation. 100% coverage through business behavior. **Quick reference:** - Write tests first (TDD non-negotiable) - Test through public API exclusively - Use factory functions for test data (no `let`/`beforeEach`) - Tests must document expected business behavior - No 1:1 mapping between test files and implementation files For detailed testing patterns and examples, load the `testing` skill. For verifying test effectiveness through mutation analysis, load the `mutation-testing` skill. ## TypeScript Guidelines **Core principle**: Strict mode always. Schema-first at trust boundaries, types for internal logic. **Quick reference:** - No `any` types - ever (use `unknown` if type truly unknown) - No type assertions without justification - Prefer `type` over `interface` for data structures - Reserve `interface` for behavior contracts only - Define schemas first, derive types from them (Zod/Standard Schema) - Use schemas at trust boundaries, plain types for internal logic For detailed TypeScript patterns and rationale, load the `typescript-strict` skill. ## Code Style **Core principle**: Functional programming with immutable data. Self-documenting code. **Quick reference:** - No data mutation - immutable data structures only - Pure functions wherever possible - No nested if/else - use early returns or composition - No comments - code should be self-documenting - Prefer options objects over positional parameters - Use array methods (`map`, `filter`, `reduce`) over loops For detailed patterns and examples, load the `functional` skill. ## Development Workflow **Core principle**: RED-GREEN-REFACTOR in small, known-good increments. TDD is the fundamental practice. **Quick reference:** - RED: Write failing test first (NO production code without failing test) - GREEN: Write MINIMUM code to pass test - REFACTOR: Assess improvement opportunities (only refactor if adds value) - **Wait for commit approval** before every commit - Each increment leaves codebase in working state - Capture learnings as they occur, merge at end For detailed TDD workflow, load the `tdd` skill. For refactoring methodology, load the `refactoring` skill. For significant work, load the `planning` skill for three-document model (PLAN.md, WIP.md, LEARNINGS.md). ## Working with Claude **Core principle**: Think deeply, follow TDD strictly, capture learnings while context is fresh. **Quick reference:** - ALWAYS FOLLOW TDD - no production code without failing test - Assess refactoring after every green (but only if adds value) - Update CLAUDE.md when introducing meaningful changes - Ask "What do I wish I'd known at the start?" after significant changes - Document gotchas, patterns, decisions, edge cases while context is fresh For detailed TDD workflow, load the `tdd` skill. For refactoring methodology, load the `refactoring` skill. For detailed guidance on expectations and documentation, load the `expectations` skill. ## Resources and References - [TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/intro.html) - [Testing Library Principles](https://testing-library.com/docs/guiding-principles) - [Kent C. Dodds Testing JavaScript](https://testingjavascript.com/) - [Functional Programming in TypeScript](https://gcanti.github.io/fp-ts/) ## Summary The key is to write clean, testable, functional code that evolves through small, safe increments. Every change should be driven by a test that describes the desired behavior, and the implementation should be the simplest thing that makes that test pass. When in doubt, favor simplicity and readability over cleverness.
Comments
No comments yet
Be the first to share your thoughts!