typescript
TypeScript and JavaScript coding standards and best practices.
When & Why to Use This Skill
This Claude skill provides a comprehensive framework for TypeScript and JavaScript development, emphasizing strict type safety, modern syntax, and scalable architectural patterns. It enables AI agents to enforce industry-leading best practices, ensuring that codebases remain clean, maintainable, and highly performant.
Use Cases
- Automated Code Audits: Evaluating pull requests and existing codebases to ensure compliance with strict type safety, proper error handling, and modern ES6+ standards.
- Refactoring Legacy Code: Guiding the migration of legacy JavaScript or loosely typed TypeScript into robust, strictly typed code using modern patterns like discriminated unions and async/await.
- Standardizing Team Workflows: Establishing a consistent set of coding rules and architectural patterns across a development team to improve readability and reduce technical debt.
| name | typescript |
|---|---|
| description | TypeScript and JavaScript coding standards and best practices. |
TypeScript Standards
Type Safety
- Enable strict mode (
"strict": true) - Avoid
any- useunknownwhen type is uncertain - Prefer
typefor unions/intersections,interfacefor object shapes - Use const assertions for literal types:
as const - Leverage discriminated unions for state machines
Prefer Modern Syntax
- Use
const/letovervar - Arrow functions for callbacks and short functions
- Template literals over string concatenation
- Optional chaining (
?.) and nullish coalescing (??) - Destructuring for cleaner code
Functions
- Explicit return types for public APIs
- Use overloads for complex signatures
- Prefer pure functions when possible
- Keep functions small and focused (max ~20-30 lines)
- Use default parameters over conditional logic
Error Handling
- Use typed error classes
- Prefer Result/Either patterns for expected failures
- Throw for unexpected/unrecoverable errors
- Always type catch blocks:
catch (error: unknown)
Async Code
- Prefer
async/awaitover raw Promises - Use
Promise.allfor parallel operations - Handle rejection with try/catch or
.catch() - Avoid mixing callbacks and promises
- Consider
Promise.allSettledwhen partial success is acceptable
Imports & Exports
- Use named exports for most cases
- Default exports only for main module entry
- Group imports: external, internal, types
- Use barrel files (
index.ts) sparingly - Prefer absolute imports with path aliases
Best Practices
- Avoid mutation when possible
- Use
readonlyfor immutable data - Prefer composition over inheritance
- Use generics for reusable type-safe code
- Validate external data at boundaries (Zod, etc.)