
Typescript Refactor
Modernize and harden TypeScript and React 19 TSX code using 47 prioritized rules from type architecture through compiler performance.
Overview
typescript-refactor is an agent skill most often used in Build (frontend), also Ship (review) and Operate (iterate), that applies 47 TypeScript 6.0 and React 19 rules to safe refactors.
Install
npx skills add https://github.com/pproenca/dot-skills --skill typescript-refactorWhat is this skill?
- 47 rules across 9 categories prioritized from critical type architecture to incremental pitfalls
- TypeScript 6.0 coverage: satisfies, using, const type parameters, inferred predicates, isolatedDeclarations
- React 19 / TSX: ref-as-prop, ComponentProps, discriminated props, synthetic events
- Compiler-performance guidance including interfaces-over-intersections (CRITICAL rule)
- Production-realistic examples and authoritative references per rule
- TypeScript 6.0 and React 19 scope
- Rule 1.3 interfaces-over-intersections marked CRITICAL for 2-3× faster type-checking
Adoption & trust: 531 installs on skills.sh; 157 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
Your TS/TSX codebase compiles but types are loose, intersections slow the checker, and React 19 patterns are applied inconsistently across agents and edits.
Who is it for?
Solo builders on React 19 + TypeScript 6 who want agent-led refactors with explicit architectural guardrails.
Skip if: Greenfield hello-world tutorials, non-TypeScript codebases, or teams that only need a one-line lint fix without structural typing changes.
When should I use this skill?
Refactoring or modernizing TypeScript/TSX codebases where compile-time safety, React 19 typing, or compiler performance matters.
What do I get? / Deliverables
Refactors follow a prioritized rule set so types are stricter, compiler work drops, and components match current React and TypeScript semantics.
- Refactored modules aligned to prioritized typing rules
- Documented rationale tied to rule categories for future agent sessions
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Refactoring typed UI and shared modules happens most often while actively building the product frontend and shared libraries. The skill centers TSX, React 19 props, hooks, and component typing—canonical Build frontend work even when it touches shared types used elsewhere.
Where it fits
Migrate legacy class-style props to discriminated unions before shipping a new dashboard.
Run the 9-category checklist on a PR that touches shared domain types and hooks.
Reduce check-time regressions after enabling stricter compiler options in CI.
How it compares
Structured refactor rulebook for TS/React—not generic “clean up this file” chat without compile-time priorities.
Common Questions / FAQ
Who is typescript-refactor for?
Indie developers and small teams shipping SaaS or CLIs with TypeScript frontends who delegate refactors to coding agents and need consistent, high-impact typing rules.
When should I use typescript-refactor?
In Build (frontend/backend) while changing components and shared types; in Ship (review) before merge when tightening types; in Operate (iterate) when paying down TS debt after incidents or perf regressions.
Is typescript-refactor safe to install?
Treat it as editorial guidance that drives wide edits; confirm repo backups and review the Security Audits panel on this page before auto-applying large refactors.
SKILL.md
READMESKILL.md - Typescript Refactor
# TypeScript 6.0 / TSX (React 19) **Version 1.2.0** TypeScript Principal Specialist May 2026 --- ## Abstract Comprehensive TypeScript and TSX refactoring and modernization guide designed for AI agents and LLMs. Contains 47 rules across 9 categories, prioritized by impact from critical (type architecture, narrowing) to incremental (quirks and pitfalls). Each rule includes a detailed explanation, a production-realistic example, and an authoritative reference. Current to TypeScript 6.0 and React 19: covers modern TypeScript features (satisfies, using, const type parameters, inferred type predicates, isolatedDeclarations, erasable syntax, with import attributes), React/TSX component and hook typing (ref-as-prop, ComponentProps, discriminated props, synthetic events), compiler performance, and type-safe error handling. --- ## Table of Contents 1. [Type Architecture](references/_sections.md#1-type-architecture) — **CRITICAL** - 1.1 [Avoid Partial Type Abuse for Builder Patterns](references/arch-avoid-partial-abuse.md) — HIGH (prevents accessing properties that were never set) - 1.2 [Default to Readonly Types](references/arch-readonly-by-default.md) — HIGH (prevents accidental mutation, catches side-effect bugs at compile time) - 1.3 [Extend Interfaces Instead of Intersecting Types](references/arch-interfaces-over-intersections.md) — CRITICAL (2-3× faster type-checking, detects property conflicts) - 1.4 [Use as const for Immutable Literal Inference](references/arch-const-assertion.md) — HIGH (prevents type widening, enables literal-based narrowing) - 1.5 [Use Branded Types for Domain Identifiers](references/arch-branded-types.md) — CRITICAL (prevents cross-domain ID mix-ups at compile time) - 1.6 [Use Discriminated Unions Over String Enums](references/arch-discriminated-unions.md) — CRITICAL (eliminates entire classes of invalid state bugs) - 1.7 [Use satisfies for Config Objects Instead of Type Annotations](references/arch-satisfies-over-annotation.md) — CRITICAL (preserves literal types while validating structure) 2. [Type Narrowing & Guards](references/_sections.md#2-type-narrowing-&-guards) — **CRITICAL** - 2.1 [Eliminate as Casts with Proper Narrowing Chains](references/narrow-eliminate-as-casts.md) — HIGH (removes 80-90% of type assertions through control flow) - 2.2 [Enforce Exhaustive Switch with never](references/narrow-exhaustive-switch.md) — CRITICAL (prevents silent fallthrough when union members expand) - 2.3 [Narrow with the in Operator for Interface Unions](references/narrow-in-operator.md) — HIGH (eliminates as casts with 1-line property checks) - 2.4 [Use Assertion Functions for Precondition Checks](references/narrow-assertion-functions.md) — CRITICAL (narrows types while validating invariants in a single call) - 2.5 [Write Custom Type Guards Instead of Type Assertions](references/narrow-custom-type-guards.md) — CRITICAL (eliminates unsafe as casts with runtime-verified narrowing) 3. [Modern TypeScript](references/_sections.md#3-modern-typescript) — **HIGH** - 3.1 [Enable verbatimModuleSyntax for Explicit Import Types](references/modern-verbatim-module-syntax.md) — MEDIUM (prevents runtime import of type-only modules) - 3.2 [Prefer Erasable Syntax Over Enums and Namespaces](references/modern-erasable-syntax.md) — HIGH (keeps code runnable under Node.js type-stripping) - 3.3 [Use Const Type Parameters for Literal Inference](references/modern-const-type-parameters.md) — HIGH (eliminates as const at call sites) - 3.4 [Use NoInfer to Control Type Parameter Inference](references/modern-noinfer-utility.md) — MEDIUM-HIGH (prevents incorrect inference from secondary parameters) - 3.5 [Use Template Literal Types for String Patterns](references/modern-template-literal-types.md) — MEDIUM-HIGH (eliminates invalid string formats at compile time) - 3.6 [Use the using Keyword for Resource Cleanup](references/modern-using-keyword.md) — HIGH (prevents resource leaks by