/typescript-magician
Designs complex generic types, refactors `any` types to strict alternatives, creates type guards and utility types, and resolves TypeScript compiler errors. Use when the user asks about TypeScript (TS) types, generics, type inference, type guards, removing `any` types, strict
$ npx -y skills add mcollina/skills --skill typescript-magician --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/typescript-magician
Context preview
The summary Claude sees to decide when to auto-load this skill.
Designs complex generic types, refactors `any` types to strict alternatives, creates type guards and utility types, and resolves TypeScript compiler errors. Use when the user asks about TypeScript (TS) types, generics, type inference, type guards, removing `any` types, strict
SKILL.md
typescript-magician.SKILL.mdname: typescript-magician
description: Designs complex generic types, refactors `any` types to strict alternatives, creates type guards and utility types, and resolves TypeScript compiler errors. Use when the user asks about TypeScript (TS) types, generics, type inference, type guards, removing `any` types, strict typing, type errors, `infer`, `extends`, conditional types, mapped types, template literal types, branded/opaque types, or utility types like `Partial`, `Record`, `ReturnType`, and `Awaited`.
metadata:
tags: typescript, types, generics, type-safety, advanced-typescript
When to use
Use this skill for:
- TypeScript errors and type challenges
- Eliminating `any` types from codebases
- Complex generics and type inference issues
- When strict typing is needed
Instructions
When invoked: 1. Run `tsc --noEmit` to capture the full error output before making changes 2. Identify the root cause of type issues (unsound inference, missing constraints, implicit `any`, etc.) 3. Craft precise, type-safe solutions using advanced TypeScript features 4. Eliminate all `any` types with proper typing — validate each replacement still satisfies call sites 5. Confirm the fix compiles cleanly with a second `tsc --noEmit` pass
Capabilities include:
- Advanced generics and conditional types
- Template literal types and mapped types
- Utility types and type manipulation
- Brand types and nominal typing
- Complex inference patterns
- Variance and distribution rules
- Module augmentation and declaration merging
For every TypeScript challenge:
- Explain the type theory behind the problem
- Provide multiple solution approaches when applicable
- Show before/after type representations
- Include comprehensive type tests
- Ensure full IntelliSense support
Quick Examples
Eliminating `any` with generics
**Before**
function getProperty(obj: any, key: string): any {
return obj[key];
}**After**
function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
return obj[key];
}
// getProperty({ name: "Alice" }, "name") → inferred as string ✓Narrowing an unknown API response
**Before**
async function fetchUser(): Promise<any> {
const res = await fetch("/api/user");
return res.json();
}**After**
interface User { id: number; name: string }
function isUser(value: unknown): value is User {
return (
typeof value === "object" &&
value !== null &&
"id" in value &&
"name" in value
);
}
async function fetchUser(): Promise<User> {
const res = await fetch("/api/user");
const data: unknown = await res.json();
if (!isUser(data)) throw new Error("Invalid user shape");
return data;
}Reference
Read individual rule files for detailed explanations and code examples:
Core Patterns
- [rules/as-const-typeof.md](rules/as-const-typeof.md) - Deriving types from runtime values using `as const` and `typeof`
- [rules/array-index-access.md](rules/array-index-access.md) - Accessing array element types using `[number]` indexing
- [rules/utility-types.md](rules/utility-types.md) - Built-in utility types: Parameters, ReturnType, Awaited, Omit, Partial, Record
Advanced Generics
- [rules/generics-basics.md](rules/generics-basics.md) - Fundamentals of generic types, constraints, and inference
- [rules/builder-pattern.md](rules/builder-pattern.md) - Type-safe builder pattern with chainable methods
- [rules/deep-inference.md](rules/deep-inference.md) - Achieving deep type inference with F.Narrow and const type parameters
Type-Level Programming
- [rules/conditional-types.md](rules/conditional-types.md) - Conditional types for type-level if/else logic
- [rules/infer-keyword.md](rules/infer-keyword.md) - Using `infer` to extract types within conditional types
- [rules/template-literal-types.md](rules/template-literal-types.md) - String manipulation at the type level
- [rules/mapped-types.md](rules/mapped-types.md) - Creating new types by transforming existing type properties
Type Safety Patterns
- [rules/opaque-types.md](rules/opaque-types.md) - Brand types and opaque types for type-safe identifiers
- [rules/type-narrowing.md](rules/type-narrowing.md) - Narrowing types through control flow analysis
- [rules/function-overloads.md](rules/function-overloads.md) - Using function overloads for complex function signatures
Debugging
- [rules/error-diagnosis.md](rules/error-diagnosis.md) - Strategies for diagnosing and understanding TypeScript type errors
Read more
name: typescript-magician description: Designs complex generic types, refactors `any` types to strict alternatives, creates type guards and utility types, and resolves TypeScript compiler errors. Use when the user asks about TypeScript (TS) types, generics, type inference, type guards, removing `any` types, strict typing, type errors, `infer`, `extends`, conditional types, mapped types, template literal types, branded/opaque types, or utility types like `Partial`, `Record`, `ReturnType`, and `Awaited`. metadata: tags: typescript, types, generics, type-safety, advanced-typescript
When to use
Use this skill for:
- TypeScript errors and type challenges
- Eliminating `any` types from codebases
- Complex generics and type inference issues
- When strict typing is needed
Instructions
When invoked: 1. Run `tsc --noEmit` to capture the full error output before making changes 2. Identify the root cause of type issues (unsound inference, missing constraints, implicit `any`, etc.) 3. Craft precise, type-safe solutions using advanced TypeScript features 4. Eliminate all `any` types with proper typing — validate each replacement still satisfies call sites 5. Confirm the fix compiles cleanly with a second `tsc --noEmit` pass
Capabilities include:
- Advanced generics and conditional types
- Template literal types and mapped types
- Utility types and type manipulation
- Brand types and nominal typing
- Complex inference patterns
- Variance and distribution rules
- Module augmentation and declaration merging
For every TypeScript challenge:
- Explain the type theory behind the problem
- Provide multiple solution approaches when applicable
- Show before/after type representations
- Include comprehensive type tests
- Ensure full IntelliSense support
Quick Examples
Eliminating `any` with generics
**Before**
function getProperty(obj: any, key: string): any {
return obj[key];
}**After**
function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
return obj[key];
}
// getProperty({ name: "Alice" }, "name") → inferred as string ✓Narrowing an unknown API response
**Before**
async function fetchUser(): Promise<any> {
const res = await fetch("/api/user");
return res.json();
}**After**
interface User { id: number; name: string }
function isUser(value: unknown): value is User {
return (
typeof value === "object" &&
value !== null &&
"id" in value &&
"name" in value
);
}
async function fetchUser(): Promise<User> {
const res = await fetch("/api/user");
const data: unknown = await res.json();
if (!isUser(data)) throw new Error("Invalid user shape");
return data;
}Reference
Read individual rule files for detailed explanations and code examples:
Core Patterns
- [rules/as-const-typeof.md](rules/as-const-typeof.md) - Deriving types from runtime values using `as const` and `typeof`
- [rules/array-index-access.md](rules/array-index-access.md) - Accessing array element types using `[number]` indexing
- [rules/utility-types.md](rules/utility-types.md) - Built-in utility types: Parameters, ReturnType, Awaited, Omit, Partial, Record
Advanced Generics
- [rules/generics-basics.md](rules/generics-basics.md) - Fundamentals of generic types, constraints, and inference
- [rules/builder-pattern.md](rules/builder-pattern.md) - Type-safe builder pattern with chainable methods
- [rules/deep-inference.md](rules/deep-inference.md) - Achieving deep type inference with F.Narrow and const type parameters
Type-Level Programming
- [rules/conditional-types.md](rules/conditional-types.md) - Conditional types for type-level if/else logic
- [rules/infer-keyword.md](rules/infer-keyword.md) - Using `infer` to extract types within conditional types
- [rules/template-literal-types.md](rules/template-literal-types.md) - String manipulation at the type level
- [rules/mapped-types.md](rules/mapped-types.md) - Creating new types by transforming existing type properties
Type Safety Patterns
- [rules/opaque-types.md](rules/opaque-types.md) - Brand types and opaque types for type-safe identifiers
- [rules/type-narrowing.md](rules/type-narrowing.md) - Narrowing types through control flow analysis
- [rules/function-overloads.md](rules/function-overloads.md) - Using function overloads for complex function signatures
Debugging
- [rules/error-diagnosis.md](rules/error-diagnosis.md) - Strategies for diagnosing and understanding TypeScript type errors
Repo: mcollina/skills
Other skills on mcollina-skills.
- /documentation
Creates, structures, and reviews technical documentation following the Diátaxis framework (tutorials, how-to guides, reference, and explanation pages). Use when a user needs to write or reorganize docs, structure a tutorial vs. a how-to guide, build reference docs or API
Open skill - /fastify
Guides development of Fastify Node.js backend servers and REST APIs using TypeScript or JavaScript. Use when building, configuring, or debugging a Fastify application — including defining routes, implementing plugins, setting up JSON Schema validation, handling errors,
Open skill - /init
Creates, updates, or optimizes an AGENTS.md file for a repository with minimal, high-signal instructions covering non-discoverable coding conventions, tooling quirks, workflow preferences, and project-specific rules that agents cannot infer from reading the codebase. Use when
Open skill - /linting-neostandard-eslint9
Configures ESLint v9 flat config and neostandard for JavaScript and TypeScript projects, including migrating from legacy `.eslintrc*` files or the `standard` package. Use when you need to set up or fix linting with `eslint.config.js` or `eslint.config.mjs`, troubleshoot lint
Open skill - /node
Provides domain-specific best practices for Node.js development with TypeScript, covering type stripping, async patterns, error handling, streams, modules, testing, performance, caching, logging, and more. Use when setting up Node.js projects with native TypeScript support,
Open skill - /nodejs-core
Contributes to and debugs Node.js core, including nodejs/node commit and PR tone, contribution workflows, native crashes, V8 performance, node-gyp builds, N-API bindings, and libuv issues. Use when drafting or reviewing a Node.js core commit or pull request, working in
Open skill

