typescript-advanced-types

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

Updated Mar 24, 2026
One-click install
npx skills add https://github.com/samline/forms --skill typescript-advanced-types-samline
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: typescript-advanced-types
Source: https://github.com/samline/forms/tree/main/example/.agents/skills/typescript-advanced-types
Command: npx skills add https://github.com/samline/forms --skill typescript-advanced-types-samline

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing complex TypeScript logic without deep type-system knowledge leads to unsafe any casts, duplicated type definitions, and runtime errors that the compiler could have caught. This Skill provides patterns and reference implementations for TypeScript's advanced type system so you can enforce correctness 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, builder patterns, deep readonly/partial utilities, form validation, and discriminated-union state machines. - Type Inference & Testing: Type guards, assertion functions, and compile-time type assertion helpers to verify type behavior. - Use Case: When building a type-safe API client where each endpoint has distinct params, body, and response types, use the conditional-type and infer patterns to extract and enforce those types automatically. ## Quick Start Ask the AI to help you implement a type-safe event emitter or generic utility type in TypeScript using advanced type system features.

Frequently Asked Questions about typescript-advanced-types

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use generics in TypeScript functions?▼

Generics let you parameterize types, like `function identity<T>(value: T): T`, so one function works with many types while preserving type information. Add constraints with `extends` (e.g., `T extends HasLength`) to require specific properties on the type parameter.

How to create conditional types with infer in TypeScript?▼

Conditional types use the form `T extends U ? X : Y` to select a type based on a condition. The `infer` keyword extracts a type inside the condition, such as `type ReturnType<T> = T extends (...args: any[]) => infer R ? R : never`.

What is the difference between mapped types and utility types in TypeScript?▼

Mapped types are the syntax `{ [P in keyof T]: T[P] }` for transforming object types, while utility types like Partial, Pick, and Omit are built-in mapped types provided by TypeScript. You can write custom mapped types with key remapping using `as` for filtering or renaming properties.

Does TypeScript type safety work at runtime?▼

No, TypeScript types are erased at compile time and provide no runtime guarantees. For runtime safety, combine types with type guards, assertion functions, or validation logic that checks values during execution.

Why do complex conditional types slow down TypeScript compilation?▼

Deeply nested conditional types and recursive type definitions force the compiler to evaluate many type branches, increasing check time. Mitigate this by simplifying types, caching computed types in aliases, and limiting recursion depth.

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

Use `unknown` whenever a value's type is not yet determined, because it forces explicit narrowing through type guards before use. Unlike `any`, which disables type checking entirely, `unknown` preserves compile-time safety.