typescript-advanced-types

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

1|Updated Jun 30, 2026
One-click install
npx skills add https://github.com/trutoman/Conjuros --skill typescript-advanced-types-trutoman
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-advanced-types
Source: https://github.com/trutoman/Conjuros/tree/main/.agents/skills/typescript-advanced-types
Command: npx skills add https://github.com/trutoman/Conjuros --skill typescript-advanced-types-trutoman

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing complex TypeScript logic without losing compile-time type safety is hard: reusable utilities, API clients, and form validators often fall back to any, which hides bugs until runtime. This Skill provides patterns and reference implementations for TypeScript's advanced type system so type errors are caught at compile time. ## Core Features & Use Cases - Advanced Type Patterns: Generics with constraints, conditional types with infer, mapped types with key remapping, and template literal types for string manipulation. - Production Patterns: Type-safe event emitters, API clients with typed endpoints, builder patterns with compile-time completeness checks, deep readonly/partial utilities, discriminated union state machines, and form validation. - Type Inference & Testing: Type guards, assertion functions, and type-level assertion helpers to verify type behavior. - Use Case: When building a typed API client where each endpoint has distinct params, body, and response shapes, use the conditional-type endpoint config pattern so incorrect request bodies fail at compile time. ## Quick Start Ask the AI to create a type-safe event emitter in TypeScript where each event name maps to a specific payload type using generics 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 interface mapping event names to payload types, then use generics with mapped types so `on` and `emit` methods infer the correct payload per event. The compiler rejects mismatched 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 from any function type for reuse in other type definitions.

What is the difference between mapped types and conditional types?

Mapped types iterate over an object'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 distributing over unions.

Should I use any or unknown in TypeScript?

Use `unknown` instead of `any` because it forces type checking before use. `any` disables all type checking and defeats TypeScript's purpose, while `unknown` requires type guards or assertions before operations.

Why do deeply nested conditional types slow down TypeScript compilation?

Deeply nested conditional types force the compiler to evaluate many type branches recursively, increasing check time. Cache complex type computations, limit recursion depth, and prefer simpler types where possible.

When should I use discriminated unions in TypeScript?

Use discriminated unions when modeling states like loading, success, or error, where a shared literal field (such as `status` or `type`) lets switch statements narrow types automatically. This gives exhaustive checking and safe property access per variant.