Master TypeScript's advanced type system including generics, conditional types, mapped types, template literals, and utility types for building type-safe app…
Install the skill above, then run this in your AI tool:
/typescript-advanced-types <your description>
About
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.
Source
What gets added to your project
Preview every file this package writes on install before you run the command above.
Summary
Master TypeScript's advanced type system including generics, conditional types, mapped types, template literals, and utility types for building type-safe applications. Use when implementing complex type logic, creating reusable type util...
Skill instructions
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: numberconst str = identity<string>("hello"); // Type: stringconst auto = identity(true); // Type inferred: boolean
Generic Constraints:
typescript
interfaceHasLength {
length: number;
}
function logLength<T extendsHasLength>(item: T): T {
console.log(item.length);
return item;
}
logLength("hello"); // OK: string has lengthlogLength([1, 2, 3]); // OK: array has lengthlogLength({ 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
typeIsString<T> = T extendsstring ? true : false;
type A = IsString<string>; // truetype B = IsString<number>; // false
// Partial<T> - Make all properties optionaltypePartialUser = Partial<User>;
// Required<T> - Make all properties requiredtypeRequiredUser = Required<PartialUser>;
// Readonly<T> - Make all properties readonlytypeReadonlyUser = Readonly<User>;
// Pick<T, K> - Select specific propertiestypeUserName = Pick<User, "name" | "email">;
// Omit<T, K> - Remove specific propertiestypeUserWithoutPassword = Omit<User, "password">;
// Exclude<T, U> - Exclude types from uniontypeT1 = Exclude<"a" | "b" | "c", "a">; // "b" | "c"// Extract<T, U> - Extract types from uniontypeT2 = Extract<"a" | "b" | "c", "a" | "b">; // "a" | "b"// NonNullable<T> - Exclude null and undefinedtypeT3 = NonNullable<string | null | undefined>; // string// Record<K, T> - Create object type with keys K and values TtypePageInfo = Record<"home" | "about", { title: string }>;
Detailed worked examples and patterns
Detailed sections (starting with ## Advanced Patterns) live in references/details.md. Read that file when the navigation summary above is insufficient.
Best Practices
Use unknown over any: Enforce type checking
Prefer interface for object shapes: Better error messages
Use type for unions and complex types: More flexible
Leverage type inference: Let TypeScript infer when possible
Create helper types: Build reusable type utilities
Use const assertions: Preserve literal types
Avoid type assertions: Use type guards instead
Document complex types: Add JSDoc comments
Use strict mode: Enable all strict compiler options
Test your types: Use type tests to verify type behavior
Add this badge to a GitHub README so readers can open the package page and install the same version.
[](https://www.aipm-registry.com/skills/wshobson/typescript-advanced-types/1.0.0?utm_source=github&utm_medium=readme&utm_campaign=package_badge)
This imported publisher has not claimed its AIPM account. A connected account confirms account control, but it does not guarantee that a package is safe.
AI assistant context
What this skill is for
@wshobson/typescript-advanced-types@1.0.0 is an AIPM skill package for All tools. Use it when a project needs the reusable AI behavior described as: Master TypeScript's advanced type system including generics, conditional types, mapped types, template literals, and utility types for building type-safe applications. Use when implementing complex type logic, creating reusable type util...
Run aipm add @wshobson/typescript-advanced-types@1.0.0 in a project that has AIPM initialized.
Supported tools
@wshobson/typescript-advanced-types@1.0.0 supports All tools.
Before installing
AIPM skills can add files to your project. Review the package name, target, description, license, and publisher before installing. Use a clean branch when trying a new skill.