typescript-advanced-types

Create conditional, mapped, and template literal types in TypeScript.

2|Updated Mar 15, 2025
One-click install
npx skills add https://github.com/dandudzi/dotfiles --skill typescript-advanced-types-dandudzi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-advanced-types
Source: https://github.com/dandudzi/dotfiles/tree/main/dot_claude/skills/typescript-advanced-types
Command: npx skills add https://github.com/dandudzi/dotfiles --skill typescript-advanced-types-dandudzi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers build more robust, maintainable, and type-safe applications by leveraging the full power of TypeScript's advanced type system.

Core Features & Use Cases

  • Conditional Types: Create types that adapt based on input types.
  • Mapped Types: Transform existing object types (e.g., make properties optional or readonly).
  • Template Literal Types: Define string patterns for type safety (e.g., event names, API paths).
  • Infer Keyword: Extract component types from complex generic types.
  • Discriminated Unions: Model state machines and result types for type-safe handling.
  • Use Case: Building a type-safe API client where endpoint paths, HTTP methods, request bodies, and response types are all strictly enforced by TypeScript.

Quick Start

Use the typescript-advanced-types skill to generate a type for a function that takes a generic array and returns its element type.

Frequently Asked Questions about typescript-advanced-types

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create conditional types in TypeScript to adapt dynamically based on input types?

Conditional types in TypeScript allow you to create types that adapt dynamically based on input types. You can use the extends keyword to check conditions and infer to extract component types from complex generic structures for strict type safety.

What is the best way to build a type-safe API client with strictly enforced endpoint paths and response types?

Building a type-safe API client involves using template literal types to enforce string patterns like endpoint paths. You combine this with discriminated unions and generics to strictly handle HTTP methods, request bodies, and response types.

How do I use mapped types to transform existing object properties to readonly or optional in TypeScript?

Mapped types in TypeScript allow you to transform existing object types by iterating over their properties. You can apply modifiers like readonly or optional to systematically alter property signatures and build reusable generic components.

How do you model state machines and result types for type-safe handling in TypeScript?

You model state machines in TypeScript by defining discriminated unions. This allows you to represent various states and result types, ensuring that all state transitions are strictly enforced and handled safely by the compiler.

Do I need prior knowledge of generic programming to use advanced TypeScript type manipulation?

Yes, mastering advanced TypeScript types requires a solid understanding of type manipulation and generic programming principles. This foundational knowledge is essential for solving complex type inference problems and building type-safe libraries.

How do I extract the element type from a generic array using the infer keyword in TypeScript?

You extract the element type from a generic array by using the infer keyword within a conditional type. This enables complex type inference by capturing and isolating specific component types from larger generic structures.