typescript-refactor

Enforce safe type architecture and modern TypeScript idioms during refactoring.

Updated Mar 26, 2026
One-click install
npx skills add https://github.com/moughamir/justwaitit-review --skill typescript-refactor-moughamir
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-refactor
Source: https://github.com/moughamir/justwaitit-review/tree/main/.agents/skills/typescript-refactor
Command: npx skills add https://github.com/moughamir/justwaitit-review --skill typescript-refactor-moughamir

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill solves the problem of unsafe or inconsistent TypeScript refactors by providing principled, high-impact guidelines that improve type safety, correctness, and compiler performance.

Core Features & Use Cases

  • Type Architecture Rules: Use discriminated unions, branded types, and satisfies to make invalid states unrepresentable and preserve literal precision.
  • Type Narrowing & Guard Patterns: Prefer custom type guards, exhaustive switches with never, and narrowing chains to eliminate unsafe as-casts.
  • Modern TypeScript & Performance Practices: Adopt newer language features (like using, accessor, const type parameters) and apply compiler-performance patterns (avoid deep recursion, prefer interfaces over intersections).

Quick Start

Use the typescript-refactor skill to refactor a TypeScript module while ensuring discriminated unions, safe narrowing, and modern idiomatic patterns are applied consistently.

Frequently Asked Questions about typescript-refactor

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

FAQPage Schema
How do I refactor TypeScript to use discriminated unions and eliminate unsafe as-casts?

Refactor TypeScript by applying custom type guards, exhaustive switches with never, and narrowing chains to eliminate unsafe as-casts. Enforce discriminated unions and branded types to make invalid states unrepresentable and ensure safe type architecture.

What is the best way to improve TypeScript compiler performance during a large module refactoring?

Improve TypeScript compiler performance during refactoring by adopting patterns that avoid deep recursion and preferring interfaces over intersections. Apply modern idiomatic practices to reduce compilation overhead and maintain type safety.

How does exhaustive checking with never work in TypeScript narrowing?

Exhaustive checking with never works by ensuring all union members are handled in switch statements, using the never type to catch unhandled cases at compile time. It eliminates unsafe casts by enforcing complete type narrowing chains.

Can I use modern TypeScript features like using and const type parameters when refactoring older code?

Yes, you can adopt modern TypeScript features like using, accessor, and const type parameters when refactoring older code. Apply these newer language features alongside satisfies to preserve literal precision and improve type architecture safely.

Why does TypeScript refactoring often break type safety and how can I prevent it?

TypeScript refactoring breaks type safety when inconsistent patterns allow invalid states or unsafe casts. Prevent it by enforcing principled guidelines: use discriminated unions, custom type guards, exhaustive checks, and branded types to make invalid states unrepresentable.

When should I not use type predicates for narrowing in TypeScript?

Avoid type predicates when exhaustive switches or built-in narrowing chains suffice, as overuse can complicate type architecture. Prefer them for custom guards that eliminate unsafe as-casts, ensuring reliable narrowing without unnecessary complexity.