| 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:
- Run
tsc --noEmit to capture the full error output before making changes
- Identify the root cause of type issues (unsound inference, missing constraints, implicit
any, etc.)
- Craft precise, type-safe solutions using advanced TypeScript features
- Eliminate all
any types with proper typing — validate each replacement still satisfies call sites
- 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];
}
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
Advanced Generics
Type-Level Programming
Type Safety Patterns
Debugging