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 utilities, or ensuring compile-time type safety in TypeScript projects.
Just instructions. No commands, network, or file access.
Files
SKILL.md
typescript-advanced-types
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 utilities, or ensuring compile-time type safety in TypeScript projects.
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:
function identity<T>(value: T): T {
return value;
}
const num = identity<number>(42); // Type: numberconst str = identity<string>("hello");
auto = ();
2 files · 17 KB8 KB
Install
It’s free, and every skill you add syncs into every AI tool on your computer, instantly.
// 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