Skip to content

Commit 3a17734

Browse files
shinprclaude
andcommitted
docs: Apply Japanese version improvements to English TypeScript rules
To maintain consistency between Japanese and English versions, applied the following improvements: 1. Added type guard implementation pattern - Clarified concrete usage of unknown type - Demonstrated safe validation of external input 2. Clarified class usage criteria - Added concrete decision criterion: "Does this data have behavior?" - Specified cases requiring state management (ShoppingCart, Session, etc.) 3. Added external API exception to type complexity management - External API types are exceptions to 20-field limit - Clarified boundary with appropriate internal conversion Adjusted to English expressions that are clear for Claude Code, and achieved complete structural alignment between Japanese and English versions (both files are 177 lines). 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 7b41c86 commit 3a17734

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

docs/rules-en/typescript.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@
2121
3. **Union Types・Intersection Types**: Combinations of multiple types
2222
4. **Type Assertions (Last Resort)**: Only when type is certain
2323

24+
**Type Guard Implementation Pattern**
25+
```typescript
26+
// Safely validate external input
27+
function isUser(value: unknown): value is User {
28+
return typeof value === 'object' && value !== null &&
29+
'id' in value && 'name' in value
30+
}
31+
// Usage: if (isUser(data)) { /* data is typed as User */ }
32+
```
33+
2434
**Modern Type Features**
2535
- **satisfies Operator**: Type check while preserving type inference
2636
```typescript
@@ -54,18 +64,22 @@
5464
Input Layer (`unknown`) → Type Guard → Business Layer (Type Guaranteed) → Output Layer (Serialization)
5565
5666
**Type Complexity Management**
57-
- Field Count: Up to 20 (split by responsibility if exceeded)
67+
- Field Count: Up to 20 (split by responsibility if exceeded, external API types are exceptions)
5868
- Optional Ratio: Up to 30% (separate required/optional if exceeded)
5969
- Nesting Depth: Up to 3 levels (flatten if exceeded)
6070
- Type Assertions: Review design if used 3+ times
71+
- **External API Types**: Relax constraints and define according to reality (convert appropriately internally)
6172
6273
## Coding Conventions
6374
6475
**Class Usage Criteria**
76+
- **Recommended: Implementation with Functions and Interfaces**
77+
- Rationale: Improves testability and flexibility of function composition
6578
- **Classes Allowed**:
6679
- Framework requirements (NestJS Controller/Service, TypeORM Entity, etc.)
6780
- Custom error class definitions
68-
- **Classes Prohibited**: Use functions and interfaces for everything else
81+
- When state and business logic are tightly coupled (e.g., ShoppingCart, Session, StateMachine)
82+
- **Decision Criterion**: If "Does this data have behavior?" is Yes, consider using a class
6983
```typescript
7084
// ✅ Functions and interfaces
7185
interface UserService { create(data: UserData): User }

0 commit comments

Comments
 (0)