typescript
SKILL.md
TypeScript Best Practices
Comprehensive performance optimization guide for TypeScript applications. Contains 42 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
- Configuring tsconfig.json for a new or existing project
- Writing complex type definitions or generics
- Optimizing async/await patterns and data fetching
- Organizing modules and managing imports
- Reviewing code for compilation or runtime performance
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Type System Performance | CRITICAL | type- |
| 2 | Compiler Configuration | CRITICAL | tscfg- |
| 3 | Async Patterns | HIGH | async- |
| 4 | Module Organization | HIGH | module- |
| 5 | Type Safety Patterns | MEDIUM-HIGH | safety- |
| 6 | Memory Management | MEDIUM | mem- |
| 7 | Runtime Optimization | LOW-MEDIUM | runtime- |
| 8 | Advanced Patterns | LOW | advanced- |
Quick Reference
1. Type System Performance (CRITICAL)
type-interfaces-over-intersections- Prefer interfaces over type intersections for faster resolutiontype-avoid-large-unions- Avoid unions with 12+ members (O(n²) checking)type-extract-conditional-types- Extract conditional types to enable cachingtype-limit-recursion-depth- Add depth limits to recursive typestype-explicit-return-types- Add explicit return types to exported functionstype-avoid-deep-generics- Flatten deeply nested generic hierarchiestype-simplify-mapped-types- Break complex mapped types into smaller utilities
2. Compiler Configuration (CRITICAL)
tscfg-enable-incremental- Enable incremental compilation for 50-90% faster rebuildstscfg-skip-lib-check- Skip declaration file checking for 20-40% faster buildstscfg-isolate-modules- Enable single-file transpilation for bundler integrationtscfg-project-references- Split large codebases into independent projectstscfg-exclude-properly- Configure include/exclude to avoid scanning unnecessary filestscfg-strict-function-types- Enable strict mode for optimized variance checks
3. Async Patterns (HIGH)
async-parallel-promises- Use Promise.all() for independent operationsasync-defer-await- Defer await until value is actually neededasync-avoid-loop-await- Avoid await inside loops, use Promise.all with mapasync-explicit-return-types- Annotate async function return typesasync-avoid-unnecessary-async- Skip async wrapper when just returning a Promise
4. Module Organization (HIGH)
module-avoid-barrel-imports- Import directly from source, not barrel filesmodule-avoid-circular-dependencies- Extract shared types to break cyclesmodule-use-type-imports- Use type-only imports for typesmodule-dynamic-imports- Use dynamic import() for large modulesmodule-control-types-inclusion- Explicitly list @types packages
5. Type Safety Patterns (MEDIUM-HIGH)
safety-prefer-unknown-over-any- Use unknown instead of any for safer handlingsafety-use-type-guards- Use type guards for runtime type checkingsafety-exhaustive-checks- Use never for exhaustive union handlingsafety-strict-null-checks- Enable strictNullChecks for null safetysafety-const-assertions- Use as const for literal type preservationsafety-assertion-functions- Use assertion functions for validation
6. Memory Management (MEDIUM)
mem-use-weakmap-for-metadata- Use WeakMap for object metadatamem-avoid-closure-leaks- Extract only needed data in closuresmem-cleanup-event-listeners- Remove event listeners on cleanupmem-avoid-global-state- Use bounded caches, avoid unbounded globalsmem-clear-timers- Clear intervals and timeouts when done
7. Runtime Optimization (LOW-MEDIUM)
runtime-use-set-for-lookups- Use Set/Map for O(1) lookupsruntime-cache-property-access- Cache property access in loopsruntime-avoid-object-spread-in-loops- Avoid spreading objects in hot loopsruntime-use-for-of-for-iteration- Use for-of for clean array iterationruntime-prefer-array-methods- Prefer native array methods over lodashruntime-use-string-methods- Use modern string methods (startsWith, includes)
8. Advanced Patterns (LOW)
advanced-branded-types- Use branded types for type-safe IDsadvanced-template-literal-types- Use template literals for string patternsadvanced-satisfies-operator- Use satisfies for validation with inference
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
- Example: type-interfaces-over-intersections
Full Compiled Document
For the complete guide with all rules expanded: AGENTS.md
Weekly Installs
4
Repository
smithery/aiFirst Seen
14 days ago
Security Audits
Installed on
claude-code2
windsurf1
cursor1