typescript-advanced-types
Master TypeScript's advanced type system including generics, conditional types, mapped types, template literals, and utility types for building type-safe applications. Use when implementing complex type logic, creating reusable type utilities, or ensuring compile-time type safety in TypeScript proje
By wshobson · 74,114 installs
npx skills add wshobson/agents --skill typescript-advanced-types
Source repository · Upstream listing
TypeScript Advanced Types
Comprehensive guidance for mastering TypeScript's advanced type system including generics, conditional types, mapped types, template literal types, and utility types for building robust, type safe applications.
When to Use This Skill
Building type safe libraries or frameworks
Creating reusable generic components
Implementing complex type inference logic
Designing type safe API clients
Building form validation systems
Creating strongly typed configuration objects
Implementing type safe state management
Migrating JavaScript codebases to TypeScript
Core Concepts
1. Generics
Purpose: Create reusable, type flexible components while maintaining type safety.
Basic Generic Function:
Generic Constraints:
Multiple Type Parameters:
2. Conditional Types
Purpose: Create types that depend on conditions, enabling sophisticated type logic.
Basic Conditional Type:
Extracting Return Types:
Distributive Conditional Types:
Nested Conditions:
3. Mapped Types
Purpose: Transform existing types by iterating over their properties.
Basic Mapped Type:
Optional Properties:
Key Remapping:
Filtering Properties:
4. Template Literal Types
Purpose: Create string based types with pattern matching and transformation.
Basic Template Literal:
String Manipulation:
Path Building:
5. Utility Types
Built in Utility Types:
Detailed worked examples and patterns
Detailed sections (starting with Advanced Patterns ) live in references/details.md . Read that file when the navigation summary above is insufficient.
Best Practices
1. Use unknown over any : Enforce type checking
2. Prefer interface for object shapes : Better error messages
3. Use type for unions and complex types : More flexible
4. Leverage type inference : Let TypeScript infer when possible
5. Create helper types : Build reusable type utilities
6. Use const assertions : Preserve literal types
7. Avoid type assertions : Use type guards instead
8. Document complex types : Add JSDoc comments
9. Use strict mode : Enable all strict compiler options
10. Test your types : Use type tests to verify type behavior
Type Testing
Common Pitfalls
1. Over using any : Defeats the purpose of TypeScript
2. Ignoring strict null checks : Can lead to runtime errors
3. Too complex types : Can slow down compilation
4. Not using discriminated unions : Misses type narrowing opportunities
5. Forgetting readonly modifiers : Allows unintended mutations
6. Circular type references : Can cause compiler errors
7. Not handling edge cases : Like empty arrays or null values
Performance Considerations
Avoid deeply nested conditional types
Use simple types when possible
Cache complex type computations
Limit recursion depth in recursive types
Use build tools to skip type checking in production