typescript-advanced-types

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

Updated Jan 9, 2026
One-click install
npx skills add https://github.com/amitpo23/cfo --skill typescript-advanced-types-amitpo23
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-advanced-types
Source: https://github.com/amitpo23/cfo/tree/main/.cursor/skills/typescript-advanced-types
Command: npx skills add https://github.com/amitpo23/cfo --skill typescript-advanced-types-amitpo23

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing complex TypeScript type logic without guidance leads to unsafe casts, overuse of any, and brittle type definitions that fail at compile time or silently allow runtime errors. ## Core Features & Use Cases - Advanced Type Patterns: Provides working implementations of generics, conditional types, mapped types, template literal types, and utility types with inference via the infer keyword. - Production-Ready Patterns: Includes type-safe event emitters, API clients, builders, deep readonly/partial transforms, form validators, and discriminated-union state machines. - Use Case: When building a type-safe API client where each endpoint has distinct params, body, and response shapes, apply the endpoint-config pattern to get full compile-time checking of every request. ## Quick Start Ask the AI to design a type-safe event emitter or API client in TypeScript using generics and conditional types.

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 type pairing event names with payload shapes, then use a generic class keyed on that map so on() and emit() enforce correct payload types per event. The compiler rejects mismatched payloads at call sites.

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. This extracts the return type of any function type, and the same infer pattern works for parameters, array elements, and promise values.

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 using extends, enabling logic like extracting types or distributing over unions.

Should I use any or unknown for untyped values in TypeScript?

Use unknown instead of any because unknown forces type narrowing through guards before use, preserving type safety. The any type disables all checking and can hide runtime errors.

Why do deeply nested conditional types slow down TypeScript compilation?

Deeply nested or recursive conditional types force the compiler to evaluate many type instantiations, increasing check time. Mitigate this by simplifying type logic, caching intermediate type aliases, and limiting recursion depth.