typescript-magician

Resolves TypeScript type errors and refactors any types into strict generic alternatives.

2|Updated Jul 25, 2026
One-click install
npx skills add https://github.com/ankaboot-source/boucle --skill typescript-magician-ankaboot-source
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-magician
Source: https://github.com/ankaboot-source/boucle/tree/main/.jcode/skills/typescript-magician
Command: npx skills add https://github.com/ankaboot-source/boucle --skill typescript-magician-ankaboot-source

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? TypeScript codebases accumulate any types, cryptic compiler errors, and weak inference that erode type safety. This Skill diagnoses the root cause of type issues and rewrites them using generics, conditional types, type guards, and utility types so code compiles cleanly under strict mode. ## Core Features & Use Cases - Type Error Diagnosis: Runs tsc --noEmit before and after changes to capture full error output, identify root causes like unsound inference or missing constraints, and verify fixes compile cleanly. - any Elimination: Replaces any with precise generics, unknown plus type guards, or branded/opaque types while validating that call sites still type-check. - Advanced Type-Level Programming: Provides reference rules for conditional types, infer, template literal types, mapped types, function overloads, builder patterns, and deep inference with const type parameters. - Use Case: A function like getProperty(obj: any, key: string): any is rewritten as getProperty<T, K extends keyof T>(obj: T, key: K): T[K], giving full autocomplete and compile-time key validation. ## Quick Start Ask the assistant to fix the TypeScript errors in your project and replace all any types with strict, type-safe alternatives.

Frequently Asked Questions about typescript-magician

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I remove any types from TypeScript code?

Replace `any` with generics that preserve inference, such as `function getProperty<T, K extends keyof T>(obj: T, key: K): T[K]`. For untrusted data, use `unknown` combined with a type guard like `value is User` to narrow safely before use.

How to fix TypeScript type errors step by step?

Run `tsc --noEmit` to capture the full error list, then read each error bottom-up since the root cause is usually at the bottom. Simplify complex expressions, add explicit type annotations to isolate the mismatch, and re-run the compiler to confirm the fix.

What is the infer keyword used for in TypeScript?

The `infer` keyword captures a type inside a conditional type, like `type ArrayElement<T> = T extends (infer U)[] ? U : never`. It enables extracting return types, parameter types, promise values, and substrings from template literal types.

Does TypeScript support nominal typing for IDs?

TypeScript uses structural typing by default, but you can simulate nominal typing with branded or opaque types like `type UserId = string & { __brand: "UserId" }`. This prevents accidentally passing a PostId where a UserId is expected.

Why does TypeScript widen my literal types to string?

TypeScript widens object and array literals during inference unless you use `as const` or a `const` type parameter (TypeScript 5.0+). Adding `as const` preserves literal types and makes the value deeply readonly.

When should I use function overloads instead of union types?

Use overloads when the return type depends on the input type, such as wrapping `document.querySelector` to return specific element types. If the return type is the same for all inputs, a simple union parameter type is clearer.