typescript-advanced-types

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

Updated Mar 14, 2026
One-click install
npx skills add https://github.com/Ishaq74/atomic --skill typescript-advanced-types-ishaq74
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-advanced-types
Source: https://github.com/Ishaq74/atomic/tree/main/.github/skills/typescript-advanced-types
Command: npx skills add https://github.com/Ishaq74/atomic --skill typescript-advanced-types-ishaq74

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 strongly-typed libraries, APIs, and applications. ## 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, the infer keyword, 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 provided APIClient pattern so invalid calls fail at compile time instead of runtime. ## Quick Start Ask the AI to implement a type-safe event emitter or API client in TypeScript using generics and conditional types from this 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 type-safe generic functions in TypeScript?

Define a type parameter like `function identity<T>(value: T): T` and constrain it with `extends` when needed, such as `T extends HasLength`. TypeScript infers the type argument from the call site, preserving type safety without explicit annotations.

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 myFunction` yields the exact return type, which stays in sync when the function changes.

What is the difference between mapped types and conditional types?

Mapped types iterate over an existing type's properties to transform them, like `Partial<T>` or key remapping with `as`. Conditional types select a type based on a check, like `T extends string ? A : B`, and distribute over unions.

When should I use unknown instead of any in TypeScript?

Use `unknown` for values whose type is not yet known, because it forces type narrowing through guards before use. `any` disables all type checking and should be avoided since it defeats TypeScript's compile-time safety.

Why do deeply nested conditional types slow down TypeScript compilation?

Each conditional branch multiplies the type-checking work the compiler performs, and recursive types compound this cost. Cache complex type computations in named aliases, limit recursion depth, and prefer simpler types where possible.

How do I verify TypeScript types behave correctly without running code?

Write compile-time type tests using an assertion helper like `type AssertEqual<T, U> = [T] extends [U] ? ([U] extends [T] ? true : false) : false`. Assign the result to a type alias; mismatches surface as type errors during compilation.