
Typescript Advanced Types
Apply generics, conditional types, mapped types, and utility types when implementing strict TypeScript libraries, APIs, forms, or state in a product codebase.
Overview
Typescript-advanced-types is an agent skill for the Build phase that teaches generics, conditional types, mapped types, and utility types for type-safe TypeScript applications.
Install
npx skills add https://github.com/wshobson/agents --skill typescript-advanced-typesWhat is this skill?
- Covers generics, constraints, conditional types, mapped types, and template literal types
- Includes utility-type patterns for API clients, forms, validation, and configuration objects
- Oriented to libraries, frameworks, and migrating JavaScript codebases to TypeScript
- Compile-time safety focus for reusable components and complex inference
- Structured When to Use list for type-safe state and API design
Adoption & trust: 46k installs on skills.sh; 36.5k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You need reusable, inference-heavy TypeScript types but keep falling back to any or duplicated interfaces that fail at compile time.
Who is it for?
Builders implementing generic components, strict API clients, or migration from JavaScript who want agent-guided advanced typing.
Skip if: Greenfield apps that only need simple interfaces, or teams that want automatic type generation from OpenAPI without hand-written type logic.
When should I use this skill?
Implementing complex type logic, reusable type utilities, or compile-time type safety in TypeScript projects.
What do I get? / Deliverables
Your agent applies documented advanced-type patterns so libraries, APIs, forms, and config objects stay type-safe through compilation.
- Type-safe generic utilities and components in source
- Patterns applied to API clients, forms, or config models
Recommended Skills
Journey fit
Build is where typed application and library code is written; this skill is invoked during implementation, not distribution or ops. Frontend is the canonical shelf because examples emphasize components, forms, and UI-oriented generics, though patterns apply to shared backend types too.
How it compares
Deep TypeScript typing reference for agents, not a test runner or ESLint-type checker skill.
Common Questions / FAQ
Who is typescript-advanced-types for?
Solo developers and small teams building type-safe TypeScript libraries, frontends, or API layers who want structured advanced-type guidance in the agent.
When should I use typescript-advanced-types?
During Build when implementing generics, conditional or mapped types, utility-type helpers, form validation typing, or JS-to-TS migrations that need compile-time safety.
Is typescript-advanced-types safe to install?
It is primarily documentation for the agent; review the Security Audits panel on this Prism page like any catalog skill before enabling it in your environment.
SKILL.md
READMESKILL.md - Typescript Advanced Types
# TypeScript Advanced Types Comprehensive guidance for mastering TypeScript's advanced type system including generics, conditional types, mapped types, template literal types, and utility types for building robust, type-safe applications. ## When to Use This Skill - Building type-safe libraries or frameworks - Creating reusable generic components - Implementing complex type inference logic - Designing type-safe API clients - Building form validation systems - Creating strongly-typed configuration objects - Implementing type-safe state management - Migrating JavaScript codebases to TypeScript ## Core Concepts ### 1. Generics **Purpose:** Create reusable, type-flexible components while maintaining type safety. **Basic Generic Function:** ```typescript function identity<T>(value: T): T { return value; } const num = identity<number>(42); // Type: number const str = identity<string>("hello"); // Type: string const auto = identity(true); // Type inferred: boolean ``` **Generic Constraints:** ```typescript interface HasLength { length: number; } function logLength<T extends HasLength>(item: T): T { console.log(item.length); return item; } logLength("hello"); // OK: string has length logLength([1, 2, 3]); // OK: array has length logLength({ length: 10 }); // OK: object has length // logLength(42); // Error: number has no length ``` **Multiple Type Parameters:** ```typescript function merge<T, U>(obj1: T, obj2: U): T & U { return { ...obj1, ...obj2 }; } const merged = merge({ name: "John" }, { age: 30 }); // Type: { name: string } & { age: number } ``` ### 2. Conditional Types **Purpose:** Create types that depend on conditions, enabling sophisticated type logic. **Basic Conditional Type:** ```typescript type IsString<T> = T extends string ? true : false; type A = IsString<string>; // true type B = IsString<number>; // false ``` **Extracting Return Types:** ```typescript type ReturnType<T> = T extends (...args: any[]) => infer R ? R : never; function getUser() { return { id: 1, name: "John" }; } type User = ReturnType<typeof getUser>; // Type: { id: number; name: string; } ``` **Distributive Conditional Types:** ```typescript type ToArray<T> = T extends any ? T[] : never; type StrOrNumArray = ToArray<string | number>; // Type: string[] | number[] ``` **Nested Conditions:** ```typescript type TypeName<T> = T extends string ? "string" : T extends number ? "number" : T extends boolean ? "boolean" : T extends undefined ? "undefined" : T extends Function ? "function" : "object"; type T1 = TypeName<string>; // "string" type T2 = TypeName<() => void>; // "function" ``` ### 3. Mapped Types **Purpose:** Transform existing types by iterating over their properties. **Basic Mapped Type:** ```typescript type Readonly<T> = { readonly [P in keyof T]: T[P]; }; interface User { id: number; name: string; } type ReadonlyUser = Readonly<User>; // Type: { readonly id: number; readonly name: string; } ``` **Optional Properties:** ```typescript type Partial<T> = { [P in keyof T]?: T[P]; }; type PartialUser = Partial<User>; // Type: { id?: number; name?: string; } ``` **Key Remapping:** ```typescript type Getters<T> = { [K in keyof T as `get${Capitalize<string & K>}`]: () => T[K]; }; interface Person { name: string; age: number; } type PersonGetters = Getters<Person>; // Type: { getName: () => string; getAge: () => number; } ``` **Filtering Properties:** ```typescript type PickByType<T, U> = { [K in keyof T as T[K] extends U ? K : never]: T[K]; }; interface Mixed