mcpField
M
mirror-types

mirror-types

github.com/marius-townhouseDevelopment643 installsUpdated 38w ago
Repository

About mirror-types

mirror-types is a TypeScript skill for reducing coupling to external packages by defining local copies of only the types a project needs. It is useful when external type changes could disrupt internal code, adapters, or wrappers.

Key features

  1. 01Mirror only required external types
  2. 02Reduce coupling to dependencies
  3. 03Insulate code from type changes
  4. 04Support adapters and wrappers

Use cases

  1. 01Keep internal code stable as dependency types change
  2. 02Define local types for an adapter
  3. 03Use only a subset of a package's types

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/marius-townhouse/effective-typescript-skills --skill mirror-types

After installing, type/mirror-typesin Claude Code to confirm it loaded.

Details

From the project README

Mirror Types to Sever Dependencies

Overview

When you depend on types from external packages, changes to those types can break your code. Mirroring types - creating your own local copies of external types - severs this dependency. This is useful when you only need a subset of external types or when you want to insulate yourself from external changes.

When to Use This Skill

  • Depending on external types
  • Avoiding tight coupling to external packages
  • External types might change frequently
  • Building adapters or wrappers
  • Types are only used internally

The Iron Rule

Mirror external types when you want to sever dependencies. Define only the subset you need, insulated from external changes.

Example

// BAD: Direct dependency on external type
import { ExternalUser } from 'external-library';

interface MyService {
  processUser(user: ExternalUser): void;
}

// If ExternalUser changes, your code breaks

// GOOD: Mirror the type
interface User {
  id: string;
  name: string;
  email: string;
}

interface MyService {
  processUser(user: User): void;
}

// Adapter converts external to internal type
function adaptExternalUser(external: ExternalUser): User {
  return {
    id: external.id,
    name: external.name,
    email: external.email,
  };
}

Reference

  • Effective TypeScript, 2nd Edition by Dan Vanderkam
  • Item 70: Mirror Types to Sever Dependencies

Comments

Markdown supported