typescript-advanced-types

Implements generics, conditional types, mapped types, and template literal types in TypeScript.

Updated Aug 16, 2026
One-click install
npx skills add https://github.com/Aveer/skills --skill typescript-advanced-types-aveer
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: typescript-advanced-types
Source: https://github.com/Aveer/skills/tree/main/skills/typescript-advanced-types
Command: npx skills add https://github.com/Aveer/skills --skill typescript-advanced-types-aveer

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, builders with required-field enforcement, deep readonly/partial utilities, form validators, and discriminated union state machines. - Type Inference & Testing: Demonstrates type guards, assertion functions, the infer keyword, and compile-time type assertion tests. - Use Case: When building a typed API client where each endpoint has distinct params, body, and response shapes, use the EndpointConfig pattern to get full autocomplete and compile-time errors on every request. ## Quick Start Ask the AI to implement a type-safe event emitter or deep readonly utility for your TypeScript interfaces using the advanced types skill.

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 EventMap type mapping event names to payload shapes, then use a generic class with mapped listener storage keyed by event name. The on and emit methods constrain callbacks and data to the payload type of the specific event key.

How to extract a function's return type in TypeScript?▼

Use a conditional type with infer: type ReturnType<T> = T extends (...args: any[]) => infer R ? R : never. TypeScript also ships this as a built-in utility type, and the same infer pattern works for parameters and promise resolution types.

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

Mapped types iterate over an existing type's keys to transform properties, like Partial or Readonly. Conditional types select a type based on a check, like T extends string ? A : B, and distribute over unions when the checked type is a naked type parameter.

Does TypeScript support deep readonly or deep partial types?▼

TypeScript has no built-in deep variants, but you can write recursive mapped types that check whether each property is an object and reapply the transformation. Functions and arrays need special handling to avoid breaking their structure.

Why do complex conditional types slow down TypeScript compilation?▼

Deeply nested conditional and recursive types force the compiler to evaluate many type instantiations, increasing check time. Mitigate this by caching computed types in aliases, limiting recursion depth, and preferring simpler type expressions where possible.

When should I use unknown instead of any in TypeScript?▼

Use unknown for values whose type you cannot guarantee, since it forces narrowing through type guards before use. Any disables type checking entirely and should be avoided because it silently propagates unsafe assumptions through the codebase.