typescript

whyleonardo's avatarfrom whyleonardo

TypeScript and JavaScript coding standards and best practices.

⭐0stars🔀0forks📁View on GitHub🕐Updated Jan 8, 2026

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.
nametypescript
descriptionTypeScript and JavaScript coding standards and best practices.

TypeScript Standards

Type Safety

  • Enable strict mode ("strict": true)
  • Avoid any - use unknown when type is uncertain
  • Prefer type for unions/intersections, interface for object shapes
  • Use const assertions for literal types: as const
  • Leverage discriminated unions for state machines

Prefer Modern Syntax

  • Use const/let over var
  • 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/await over raw Promises
  • Use Promise.all for parallel operations
  • Handle rejection with try/catch or .catch()
  • Avoid mixing callbacks and promises
  • Consider Promise.allSettled when 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 readonly for immutable data
  • Prefer composition over inheritance
  • Use generics for reusable type-safe code
  • Validate external data at boundaries (Zod, etc.)