typescript-advanced-types

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

1|Updated Apr 3, 2026
One-click install
npx skills add https://github.com/TierOne-Studio/spa-velocity --skill typescript-advanced-types-tierone-studio
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-advanced-types
Source: https://github.com/TierOne-Studio/spa-velocity/tree/main/.ruler/skills/typescript-advanced-types
Command: npx skills add https://github.com/TierOne-Studio/spa-velocity --skill typescript-advanced-types-tierone-studio

SYSTEM DOCUMENTATION & REQUIREMENTS

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 type narrowing opportunities. This Skill provides patterns and reference implementations for TypeScript's advanced type system so you can build type-safe libraries, API clients, and state machines. ## 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, builders with compile-time completeness checks, deep readonly/partial utilities, form validators, and discriminated-union state machines. - Type Inference & Testing: Type guards, assertion functions, and type-level assertion helpers for verifying type behavior. - Use Case: When building a typed API client, use the endpoint-config pattern to get fully inferred request params, bodies, and response types per route and HTTP method. ## Quick Start Ask the AI to implement 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 mapping event names to payload types, then use generics with `keyof` constraints so `on` and `emit` infer the correct payload type per event. This gives compile-time errors when payloads don't match the registered event shape.

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`. Passing `typeof myFunction` extracts its return type at compile time without runtime code.

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

Mapped types iterate over an object's keys to transform properties, like making them optional 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`. `unknown` forces type narrowing through guards or assertions before use, preserving compile-time safety, while `any` disables type checking entirely and can hide runtime errors.

When should I avoid deeply nested conditional types in TypeScript?

Avoid deep nesting when compilation slows noticeably or types become unreadable. Cache complex type computations in named aliases, limit recursion depth, and prefer simpler type compositions when they achieve the same safety.