typescript-coding-standards
This skill uses Claude hooks which can execute code automatically in response to events. Review carefully before installing.
TypeScript Coding Standards
Principles
Type Safety
- Enable strict mode in tsconfig.json
- Avoid 'any' type - use 'unknown' when type is truly uncertain
- Use const assertions for literal types (as const)
- Prefer type inference over explicit types when obvious
- Use discriminated unions for complex state modeling
Naming Conventions
- Use PascalCase for types, interfaces, and classes
- Use camelCase for variables, functions, and properties
- Use UPPER_SNAKE_CASE for constants
- Prefix interfaces with 'I' only when necessary to avoid conflicts
- Use descriptive names that reveal intent
Type Definitions
- Prefer interfaces for object types (extensible)
- Use type aliases for unions, intersections, and utilities
- Define types close to where they're used
- Export types from index files for library modules
- Use utility types (Partial, Pick, Omit, Record, etc.)
Function Signatures
- Always specify return types for public functions
- Use optional parameters with default values sparingly
- Prefer function overloads for complex signatures
- Use generics for reusable, type-safe functions
Error Handling
- Use typed errors with discriminated unions
- Prefer Result<T, E> pattern over throwing exceptions
- Document thrown exceptions in JSDoc comments
- Handle all error cases explicitly
Best Practices
Imports
- Use path aliases for cleaner imports (@/ prefix)
- Group imports: external -> internal -> relative
- Use named imports over default imports when possible
- Avoid circular dependencies
Code Organization
- One component/class per file (exceptions for small helpers)
- Co-locate related files (component + styles + tests)
- Use index files for barrel exports
- Keep files under 300 lines when possible
Documentation
- Use JSDoc comments for public APIs
- Document complex type definitions
- Explain non-obvious type assertions
- Keep comments up-to-date with code changes
Anti-Patterns
Avoid
- Type assertions (as Type) without justification
- Non-null assertions (!) without null checks
- Empty interfaces extending other types
- Excessive use of Pick/Omit (indicates poor type design)
- Magic numbers - use named constants
- Mutating function parameters
Code Quality
Linting
- Configure ESLint with TypeScript plugin
- Enable recommended TypeScript rules
- Use Prettier for consistent formatting
- Fix all linting errors before commit
Testing
- Type test critical type utilities
- Test type narrowing logic
- Verify discriminated unions exhaustiveness
More from masanao-ohba/claude-manifests
requirement-analyzer
Invoke when goal-clarifier analyzes user requirements to extract goals and constraints. Provides structured requirement decomposition into functional/non-functional categories, stakeholder mapping, assumption identification, and documentation format.
37test-case-designer
Invoke when test-strategist plans test coverage for CakePHP features. Produces categorized test case specifications (unit/integration/system) with CakePHP-specific fixtures, IntegrationTestTrait usage, and proper test documentation format.
26functional-designer
Invoke when design-architect creates functional specs for CakePHP features. Produces detailed technical specifications mapping requirements to CakePHP controllers, models, services, and views with data flow diagrams and API endpoint definitions.
18react-architectural-patterns
Invoke when design-architect or code-developer designs React 19 component architecture. Provides component type taxonomy, composition patterns, state management strategies, render optimization techniques, and React 19 feature guidance.
15nextjs-code-reviewer
Invoke when quality-reviewer reviews Next.js 15 App Router code. Provides framework-specific review checklist covering file organization, server/client component usage, data fetching correctness, metadata configuration, and performance patterns.
14security-patterns
Invoke when code-developer or quality-reviewer handles PHP security concerns. Provides input validation patterns, SQL injection prevention, XSS protection, CSRF mitigation, secure session management, and password hashing best practices for PHP.
14