typescript-advanced-types

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

Updated Jul 29, 2026
One-click install
npx skills add https://github.com/MaiconGambini/opencode-harness-guide --skill typescript-advanced-types-maicongambini
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-advanced-types
Source: https://github.com/MaiconGambini/opencode-harness-guide/tree/main/skills/typescript-advanced-types
Command: npx skills add https://github.com/MaiconGambini/opencode-harness-guide --skill typescript-advanced-types-maicongambini

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Designing type-safe TypeScript code becomes difficult when you need reusable generic components, complex type inference, or strongly-typed APIs, and mistakes in the type system lead to runtime errors and fragile codebases. ## Core Features & Use Cases - Advanced Type Patterns: Covers generics with constraints, conditional types with infer, mapped types with key remapping, and template literal types for string manipulation. - Production Patterns: Includes type-safe event emitters, API clients, builder patterns, deep readonly/partial utilities, form validation, and discriminated union state machines. - Type Inference & Testing: Demonstrates type guards, assertion functions, the infer keyword, and compile-time type testing helpers. - Use Case: When building a type-safe API client, use the endpoint configuration pattern to map HTTP methods and paths to typed request bodies, params, and responses so invalid calls fail at compile time. ## Quick Start Ask the assistant to help you implement a type-safe event emitter or generic utility type in TypeScript using the advanced types 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 generic functions with constraints in TypeScript?

Generic functions use type parameters like <T> to stay flexible while preserving types. Add constraints with extends, such as <T extends HasLength>, so only types meeting the constraint are accepted while inference still works automatically.

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 your function yields the exact return type at compile time.

What is the difference between mapped types and conditional types?

Mapped types iterate over an existing type's keys to transform properties, like making them readonly or optional. Conditional types select a type based on a check, such as T extends string ? A : B, enabling type-level logic.

Does TypeScript support type-safe event emitters?

Yes, by defining an event map interface and using generics with keyof, the emitter enforces correct event names and payload types at compile time. Mismatched payloads produce type errors before runtime.

When should I avoid complex conditional types in TypeScript?

Avoid deeply nested or recursive conditional types when they slow compilation or hurt readability. Prefer simpler type compositions, cache computed types, and limit recursion depth to keep build times reasonable.