π· TypeScript Project Guide
This guide covers how to make the most of ECC in TypeScript/JavaScript projects.
Quick Setupβ
1. Install the TypeScript Rule Packβ
# Copy TypeScript rules to the CodeBuddy config directory
cp -r rules/typescript/* ~/.codebuddy/rules/
2. Recommended Project Structureβ
your-project/
βββ .codebuddy/
β βββ rules/ # Project-specific rules
βββ src/
β βββ components/ # React components
β βββ hooks/ # Custom Hooks
β βββ utils/ # Utility functions
β βββ types/ # TypeScript type definitions
β βββ services/ # API services
βββ tests/
β βββ unit/ # Unit tests
β βββ e2e/ # End-to-end tests
βββ tsconfig.json
βββ package.json
Recommended Workflowβ
New Feature Developmentβ
# 1. Plan
/plan Implement user authentication feature
# 2. TDD development
/tdd --feature="user-auth"
# 3. Code review
/code-review src/auth/
# 4. End-to-end testing
/e2e Test the login flow
Bug Fixingβ
# 1. Debug
/debug TypeError: Cannot read property 'x' of undefined
# 2. TDD fix (write reproduction test first)
/tdd --feature="fix-undefined-error"
# 3. Verify
/test --coverage
Hook Configurationβ
Recommended TypeScript Hooksβ
{
"hooks": {
"postToolUse": [
{
"name": "prettier",
"trigger": "*.{ts,tsx,js,jsx}",
"command": "npx prettier --write"
},
{
"name": "tsc-check",
"trigger": "*.{ts,tsx}",
"command": "npx tsc --noEmit"
},
{
"name": "console-warn",
"trigger": "*.{ts,tsx}",
"pattern": "console.log",
"action": "warn"
}
]
}
}
Best Practicesβ
Type Safetyβ
// β
Use Zod for runtime validation
import { z } from 'zod'
const UserSchema = z.object({
id: z.string().uuid(),
email: z.string().email(),
name: z.string().min(1)
})
type User = z.infer<typeof UserSchema>
Immutable Updatesβ
// β
Use spread operator
function updateUser(user: User, name: string): User {
return { ...user, name }
}
// β Avoid direct mutation
function updateUser(user: User, name: string): User {
user.name = name // Dangerous!
return user
}
Error Handlingβ
// β
Use try-catch with meaningful error messages
try {
const result = await riskyOperation()
return result
} catch (error) {
console.error('Operation failed:', error)
throw new Error('User-friendly error message')
}
Common Commandsβ
| Scenario | Command |
|---|---|
| Start a new feature | /plan Feature description |
| TDD development | /tdd --feature="name" |
| Code review | /code-review |
| Security check | /security |
| Performance optimization | /perf |
π‘ Tip: For TypeScript projects, we recommend Vitest as the test framework and Playwright for E2E testing!