AgentSkillsCN

typescript-expert

TypeScript高级模式,用于类型安全和性能。适用于复杂的领域逻辑和API类型定义。

SKILL.md
--- frontmatter
name: typescript-expert
description: Advanced TypeScript patterns for type safety and performance. Use for complex domain logic and API type definitions.

TypeScript Expert

Write safe, self-documenting, and performant code.

1. Type Safety

  • Strict Mode: Always assume strict: true.
  • No any: Avoid any at all costs. Use unknown or generics.
  • Discriminated Unions: Use for state management and API responses.

2. Advanced Patterns

  • Generics: Use for reusable components and service layers.
  • Utility Types: Leverage Pick, Omit, Partial, and Record.
  • Type Guards: Use is for narrow type assertions.

3. Performance

  • Avoid Over-Typing: Don't type things that TS can infer.
  • Complex Types: Be careful with recursive or deeply nested types that might slow down the IDE.

4. Organization

  • Colocation: Keep types close to where they are used.
  • Shared Types: Put project-wide types in src/types/.
  • Naming: PascalCase for Interfaces and Types.