typescript-advanced-types

Implement generics, conditional types, mapped types, and template literal types in TypeScript projects.

Updated Apr 1, 2026
One-click install
npx skills add https://github.com/DCueto/zen-track --skill typescript-advanced-types-dcueto
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: typescript-advanced-types
Source: https://github.com/DCueto/zen-track/tree/main/ZenTrackApp/.agents/skills/typescript-advanced-types
Command: npx skills add https://github.com/DCueto/zen-track --skill typescript-advanced-types-dcueto

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing complex TypeScript type logic without guidance leads to unsafe casts, overuse of any, and missed compile-time guarantees. This Skill provides patterns and reference implementations for building type-safe libraries, API clients, and validation systems. ## Core Features & Use Cases - Advanced Type Patterns: Covers generics with constraints, conditional types with infer, mapped types with key remapping, and template literal types for string manipulation. - Production Patterns: Includes type-safe event emitters, API clients, builder patterns, deep readonly/partial utilities, form validators, and discriminated union state machines. - Use Case: When building a type-safe REST API client, use the endpoint configuration pattern to map paths and HTTP methods to typed params, bodies, and responses so invalid calls fail at compile time. ## Quick Start Ask the AI to help you implement a type-safe event emitter or generic utility type in your TypeScript project using these advanced type patterns.

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 a type-safe event emitter in TypeScript?▼

Define an event map interface mapping event names to payload types, then use a generic class with mapped types for the listeners record. The on and emit methods constrain event names with keyof and infer payload types automatically.

How to extract return types and parameters from functions in TypeScript?▼

Use conditional types with the infer keyword, such as T extends (...args: infer P) => infer R. TypeScript also provides built-in ReturnType and Parameters utility types for common extraction cases.

What is the difference between mapped types and conditional types?▼

Mapped types iterate over an existing type's properties using keyof to transform each field, like Partial or Readonly. Conditional types select between types based on a constraint check using extends, enabling logic like type extraction with infer.

Should I use unknown or any in TypeScript?▼

Use unknown instead of any because unknown forces type narrowing through guards before use, preserving compile-time safety. The any type disables all checking and defeats TypeScript's purpose.

Why do deeply nested conditional types slow down TypeScript compilation?▼

Each conditional branch multiplies the type-checking work the compiler performs, and recursive types compound this cost. Limit recursion depth, cache complex type computations, and prefer simpler types when possible.

When should I use discriminated unions in TypeScript?▼

Use discriminated unions when modeling states or results that share a common literal tag field, such as status or type. Switch statements on the tag give automatic type narrowing for each variant.