refactoring-typescript

Separate TypeScript business logic from I/O and external dependencies via interfaces.

Updated Jan 31, 2026
One-click install
npx skills add https://github.com/lekman/cdn --skill refactoring-typescript
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactoring-typescript
Source: https://github.com/lekman/cdn/tree/main/.claude/skills/refactoring-typescript
Command: npx skills add https://github.com/lekman/cdn --skill refactoring-typescript

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This guide provides a structured approach to separating business logic from system interactions in TypeScript, enabling cleaner architecture and easier testing.

Core Features & Use Cases

  • Identify system boundaries between business logic and external calls (I/O, HTTP, shell, DB) in TypeScript.
  • Define a conventional interface contract (e.g., I{Name}) and the corresponding domain interface file.
  • Implement a thin wrapper (domain.system.ts) that delegates to external dependencies.
  • Create a mock implementation for testing under tests/mocks/.
  • Refactor business logic to depend on the interface via dependency injection.
  • Improve test coverage by exercising the interface-based design and mocks.
  • Configure tooling to exclude the system wrapper from test coverage.

Quick Start

Identify a mixed area of business logic and system interactions, create an interface, implement a thin system wrapper, and refactor the code to depend on the interface.

Frequently Asked Questions about refactoring-typescript

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

FAQPage Schema
How do I separate business logic from I/O in TypeScript?

To separate business logic from I/O in TypeScript, identify system boundaries, define a conventional interface contract, implement a thin wrapper for external dependencies, and refactor logic to depend on the interface via dependency injection.

What is the best way to refactor TypeScript code for easier testing?

The best way to refactor TypeScript code for testing is to isolate external calls like HTTP and file systems into thin system wrappers, create mock implementations under a mocks directory, and configure tooling to exclude wrappers from coverage.

How does dependency injection improve TypeScript architecture?

Dependency injection improves TypeScript architecture by allowing business logic to depend on interface contracts rather than direct system interactions, enabling safe migrations and easier mock generation for testing.

Can I use interfaces to mock file system and HTTP calls in TypeScript?

Yes, you can use interfaces to mock file system and HTTP calls by defining a conventional interface contract, implementing a thin wrapper that delegates to external dependencies, and creating a corresponding mock implementation for your tests.

When do I need to create system wrappers in TypeScript?

You need to create system wrappers in TypeScript when you have tangled business logic mixed with system interactions like I/O, HTTP, or database calls, allowing you to isolate external dependencies and achieve observable, testable code.