typescript-advanced-types

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

Updated May 23, 2026
One-click install
npx skills add https://github.com/Oatse/CWE-Automation --skill typescript-advanced-types-oatse
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-advanced-types
Source: https://github.com/Oatse/CWE-Automation/tree/main/.agents/skills/typescript-advanced-types
Command: npx skills add https://github.com/Oatse/CWE-Automation --skill typescript-advanced-types-oatse

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 applications using TypeScript's advanced type system. ## 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 validation, 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 type-safe API client, apply the endpoint configuration pattern so request parameters, bodies, and responses are fully typed per route and HTTP method. ## 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 type mapping event names to payload types, then use generics with mapped types so on() and emit() methods infer the correct payload type per event. The compiler rejects mismatched event names or payloads at compile time.

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

Use a conditional type with the infer keyword: type ReturnType<T> = T extends (...args: any[]) => infer R ? R : never. This extracts the return type R from any function type passed as the generic argument.

What is the difference between mapped types and conditional types in TypeScript?

Mapped types iterate over an existing type's keys to transform properties, like making them readonly or optional. Conditional types select a type based on a condition using extends, enabling logic like extracting types or filtering union members.

Should I use any or unknown in TypeScript?

Use unknown instead of any because unknown forces type checking before use through type guards or assertions. The any type disables all type checking and defeats TypeScript's compile-time safety guarantees.

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 compile time. Mitigate this by caching complex type computations, limiting recursion depth, and preferring simpler types where possible.