skills/typescript-refactor/SKILL.md
TypeScript refactoring and modernization guidelines from a principal specialist perspective. This skill should be used when refactoring, reviewing, or modernizing TypeScript code to ensure type safety, compiler performance, and idiomatic patterns. Triggers on tasks involving TypeScript type architecture, narrowing, generics, error handling, or migration to modern TypeScript features.
npx skillsauth add shipshitdev/library typescript-refactorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
43 rules across 8 categories for TypeScript refactoring and modernization, prioritized by impact to guide automated refactoring, code review, and code generation.
as castssatisfies, using, const type parameters)| Priority | Category | Impact | Prefix |
|----------|----------|--------|--------|
| 1 | Type Architecture | CRITICAL | arch- |
| 2 | Type Narrowing & Guards | CRITICAL | narrow- |
| 3 | Modern TypeScript | HIGH | modern- |
| 4 | Generic Patterns | HIGH | generic- |
| 5 | Compiler Performance | MEDIUM-HIGH | compile- |
| 6 | Error Safety | MEDIUM | error- |
| 7 | Runtime Patterns | MEDIUM | perf- |
| 8 | Quirks & Pitfalls | LOW-MEDIUM | quirk- |
arch-discriminated-unions — Use discriminated unions over string enums for exhaustive pattern matchingarch-branded-types — Use branded types for domain identifiers to prevent value mix-upsarch-satisfies-over-annotation — Use satisfies for config objects to preserve literal typesarch-interfaces-over-intersections — Extend interfaces instead of intersecting types for better error messagesarch-const-assertion — Use as const for immutable literal inferencearch-readonly-by-default — Default to readonly types for function parameters and return valuesarch-avoid-partial-abuse — Avoid Partial<T> abuse for builder patternsnarrow-custom-type-guards — Write custom type guards instead of type assertionsnarrow-assertion-functions — Use assertion functions for precondition checksnarrow-exhaustive-switch — Enforce exhaustive switch with nevernarrow-in-operator — Narrow with the in operator for interface unionsnarrow-eliminate-as-casts — Eliminate as casts with proper narrowing chainsnarrow-typeof-chains — Use typeof narrowing before property accessmodern-using-keyword — Use the using keyword for resource cleanupmodern-const-type-parameters — Use const type parameters for literal inferencemodern-template-literal-types — Use template literal types for string patternsmodern-noinfer-utility — Use NoInfer to control type parameter inferencemodern-accessor-keyword — Use accessor for auto-generated getters and settersmodern-verbatim-module-syntax — Enable verbatimModuleSyntax for explicit import typesgeneric-infer-over-annotate — Let TypeScript infer instead of explicit annotationgeneric-constrain-dont-overconstrain — Constrain generics minimallygeneric-avoid-distributive-surprises — Control distributive conditional typesgeneric-mapped-type-utilities — Build custom mapped types for repeated transformationsgeneric-return-type-inference — Preserve return type inference in generic functionscompile-explicit-return-types — Add explicit return types to exported functionscompile-avoid-deep-recursion — Avoid deeply recursive type definitionscompile-project-references — Use project references for monorepo buildscompile-base-types-over-unions — Use base types instead of large union typeserror-result-type — Use Result types instead of thrown exceptionserror-exhaustive-error-handling — Use exhaustive checks for typed error variantserror-typed-catch — Type catch clause variables as unknownerror-never-for-unreachable — Use never to mark unreachable code pathserror-discriminated-error-unions — Model domain errors as discriminated unionsperf-union-literals-over-enums — Use union literals instead of enumsperf-avoid-delete-operator — Avoid the delete operator on objectsperf-object-freeze-const — Use Object.freeze with as const for true immutabilityperf-object-keys-narrowing — Avoid Object.keys type wideningperf-map-set-over-object — Use Map and Set over plain objects for dynamic collectionsquirk-excess-property-checks — Understand excess property checks on object literalsquirk-empty-object-type — Avoid the {} type — it means non-nullishquirk-type-widening-let — Prevent type widening with let declarationsquirk-variance-annotations — Use variance annotations for generic interfacesquirk-structural-typing-escapes — Guard against structural typing escape hatchesRead individual reference files for detailed explanations and code examples:
| File | Description | |------|-------------| | references/_sections.md | Category definitions and ordering | | assets/templates/_template.md | Template for new rules | | metadata.json | Version and reference information |
tools
Resolves TypeScript and JavaScript problems across type-level programming, performance, monorepo management, migration, and modern tooling. Invoke when diagnosing "type instantiation excessively deep" errors, migrating JS to TS, configuring strict tsconfig, debugging module resolution, or choosing between Biome/ESLint/Turborepo/Nx.
tools
Turborepo monorepo build system guidance. Triggers on: `turbo.json`, task pipelines, `dependsOn`, caching, remote cache, the `turbo` CLI, `--filter`, `--affected`, CI optimization, environment variables, internal packages, monorepo structure, and package boundaries. Use when the user configures tasks or workflows, creates packages, sets up a monorepo, shares code between apps, runs changed packages, debugs cache behavior, or works in an `apps/` plus `packages/` workspace.
tools
Provides Tailwind CSS v4 performance optimization and best practices guidelines. Triggers when writing, reviewing, or refactoring Tailwind CSS v4 code; when working with Tailwind configuration, @theme directive, utility classes, responsive design, dark mode, container queries, or CSS generation optimization.
testing
Reports portable validation evidence when checking a fixture skill.