typescript-advanced-types

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

Updated Aug 25, 2026
One-click install
npx skills add https://github.com/AliJ021/labelmod-core --skill typescript-advanced-types-alij021
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-advanced-types
Source: https://github.com/AliJ021/labelmod-core/tree/main/.claude/skills/typescript-advanced-types
Command: npx skills add https://github.com/AliJ021/labelmod-core --skill typescript-advanced-types-alij021

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing complex TypeScript logic without losing compile-time type safety is hard: developers often fall back to any, duplicate type definitions, or miss edge cases in generic code. This Skill provides patterns and worked examples for TypeScript's advanced type system so type-level logic stays correct and maintainable. ## Core Features & Use Cases - Generics and Constraints: Build reusable generic functions and classes with constrained type parameters and multi-parameter composition. - Conditional and Mapped Types: Extract return types, filter properties by type, remap keys, and build distributive conditional logic. - Template Literal Types: Construct string-pattern types such as event handler names and nested object path strings. - Worked Patterns: Type-safe event emitters, API clients, builders with required-field enforcement, deep readonly/partial types, form validators, and discriminated-union state machines. - Use Case: When designing a type-safe API client where each endpoint defines its own params, body, and response types, use the conditional-type extraction patterns to make every call fully typed. ## Quick Start Ask the AI to design a type-safe event emitter or API client in TypeScript using generics, conditional types, and mapped 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 types, then use generics with keyof constraints so on() and emit() only accept valid events with correctly typed data. The compiler rejects mismatched payloads at compile time.

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 from 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, such as making them readonly or optional. Conditional types select a type based on a check using extends, enabling logic like extracting types or filtering union members.

When should I use template literal types in TypeScript?

Use template literal types when string values follow patterns, such as event handler names like onClick, route paths, or nested object key paths like server.host. They combine unions and string manipulation utilities like Capitalize and Uppercase.

Why does TypeScript compilation slow down with complex types?

Deeply nested conditional types and unbounded recursive types force the compiler to evaluate large type trees. Limit recursion depth, cache computed types in aliases, and prefer simpler type expressions where inference suffices.

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

Use unknown instead of any because unknown forces type narrowing through guards or assertions before use, preserving type safety. Reserve any for migrations where strict checking is temporarily impractical.