typescript-advanced-types

Implements generics, conditional types, mapped types, and template literals for type-safe TypeScript code.

28|1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/NauelG/astro-blocks --skill typescript-advanced-types-nauelg
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: typescript-advanced-types
Source: https://github.com/NauelG/astro-blocks/tree/main/.agents/skills/typescript-advanced-types
Command: npx skills add https://github.com/NauelG/astro-blocks --skill typescript-advanced-types-nauelg

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing complex TypeScript logic without losing compile-time type safety is hard: generic APIs, dynamic event payloads, and nested configuration objects often force developers into unsafe any casts. This Skill provides patterns and reference implementations for TypeScript's advanced type system so type errors are caught at compile time instead of runtime. ## Core Features & Use Cases - Advanced Type Patterns: Covers generics with constraints, conditional types with infer, mapped types with key remapping, template literal types, and all built-in utility types. - Production Patterns: Includes type-safe event emitters, API clients, builder patterns, deep readonly/partial types, 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 typed API client where each endpoint has different params, body, and response shapes, apply the endpoint-config mapped type pattern so every request() call is fully type-checked. ## Quick Start Ask the AI to design a type-safe event emitter or API client in TypeScript using generics and conditional types from this 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 type-safe generic functions in TypeScript?▼

Declare a type parameter like `function identity<T>(value: T): T` and constrain it with `extends` when needed, such as `T extends HasLength`. TypeScript infers the type argument from the call site, preserving type safety without explicit annotations.

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`. Applying it to `typeof myFunction` yields the exact return type, which is useful for typing wrapper functions and API clients.

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

Mapped types iterate over an existing type's keys to transform properties, like `Partial<T>` or key remapping with `as`. Conditional types select a type based on a check, like `T extends string ? A : B`, and distribute over unions.

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

Use `unknown` for values whose type is not yet known, because it forces type narrowing through guards before use. `any` disables all type checking and should be avoided since it defeats compile-time safety.

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

Each conditional branch multiplies the type-checking work the compiler must perform, and recursive types amplify this exponentially. Cache complex type computations in named aliases and limit recursion depth to keep build times reasonable.

How do I build a type-safe event emitter in TypeScript?▼

Define an event map interface mapping event names to payload types, then use generic methods constrained by `keyof T` so `on` and `emit` only accept valid events with correctly typed payloads. Mismatched payloads become compile errors.