# Fabiensalles Claude Marketplace TS Refactoring

> Refactoring — TypeScript Examples

- Skill: `tomevault-io/fabiensalles-claude-marketplace-ts-refactoring` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/fabiensalles-claude-marketplace-ts-refactoring`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/fabiensalles-claude-marketplace-ts-refactoring/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/fabiensalles-claude-marketplace-ts-refactoring

---


# Refactoring — TypeScript Examples

> The **rules** are defined in `craft:refactoring-principles` (cross-language). This skill provides TypeScript / Node examples only. Load both for the full picture.

## Example — Rule 1: Trace the Complete Business Flow

```typescript
// ❌ AVOID — refactoring without understanding the full flow
const uploadFile = new UploadFile(content, fileName);

// ...but UploadFile is also created in downloadExistingFiles() with
// different data. Two inconsistent creation paths.
//
// Sources you must identify BEFORE refactoring:
//   - browser File API:  File              → UploadFile
//   - API download:      binary content    → UploadFile
//
// → The abstraction must unify both sources.
```

## Example — Rule 2: Consumer-Driven Value Object

```typescript
// ❌ AVOID — VO defined only from its creation point
class UploadFile {
  constructor(
    readonly content: Buffer,
    readonly originalFileName: string,
  ) {}
}

// Later, a consumer needs the file type → external mapping required.
//   repository.upload(file, request)
//     uses  file.content, file.originalFileName, request.fileType
//   → fileType comes from the file itself, NOT the request.

// ✅ CORRECT — include FileType because a consumer needs it
class UploadFile {
  constructor(
    readonly type: FileType,
    readonly content: Buffer,
    readonly originalFileName: string,
  ) {}
}
```

## Example — Rule 3: Imports as a Coupling Signal

```typescript
// ❌ AVOID — a domain service importing infrastructure types
import { Request, Response } from 'express';
import { PrismaClient } from '@prisma/client';

// The domain service manipulates HTTP and DB types directly.
// The imports betray a leaky abstraction.

// ✅ CORRECT — imports reflect the right abstraction level
import { UploadFile } from '../domain/upload-file';
import { TenantRepository } from '../domain/ports/tenant-repository';

// The service only manipulates domain objects. HTTP/DB type conversion
// happens at the boundaries (controllers, adapters).
```

## TypeScript-specific note

> See `ts-oop` rule #5 (Self-Descriptive Value Objects) for the branded-type pattern that complements rule 2 above.

---
> Source: [FabienSalles/claude-marketplace](https://github.com/FabienSalles/claude-marketplace) — distributed by [TomeVault](https://tomevault.io).
<!-- tomevault:4.0:skill_md:2026-06-01 -->

