mcpField
M
module-augmentation

module-augmentation

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

About module-augmentation

A TypeScript skill explaining how to extend existing module declarations with module augmentation. It is intended for developers addressing incomplete library types or adding declarations for plugins and globals.

Key features

  1. 01Extend third-party module types
  2. 02Add properties and methods to interfaces
  3. 03Support plugin type extensions
  4. 04Augment global declarations
  5. 05Use declare module for declaration merging

Use cases

  1. 01Patch incomplete library types
  2. 02Add types for a library plugin
  3. 03Extend existing interfaces
  4. 04Add declarations to global types

Install

Copy the command and run it in a terminal.

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

After installing, type/module-augmentationin Claude Code to confirm it loaded.

Details

From the project README

Use Module Augmentation to Improve Types

Overview

Module augmentation allows you to add declarations to existing modules, including third-party libraries. This is useful when a library's types are incomplete or when you're extending a library with plugins. Use declare module to add properties, methods, or types to existing modules.

When to Use This Skill

  • Extending third-party types
  • Adding properties to existing interfaces
  • Plugins that extend core types
  • Declaration merging needed
  • Augmenting global types

The Iron Rule

Use module augmentation to add to existing types. Declare the same module name and add your declarations.

Example

// Adding to an existing module
// types/vue.d.ts
declare module 'vue' {
  export interface ComponentCustomProperties {
    $myProperty: string;
    $myMethod(): void;
  }
}

// Now Vue components have these properties
// this.$myProperty works with type safety

// Augmenting global types
declare global {
  interface Window {
    myLib: MyLibrary;
  }
}

// Now window.myLib is typed

Reference

  • Effective TypeScript, 2nd Edition by Dan Vanderkam
  • Item 71: Use Module Augmentation to Improve Types

Comments

Markdown supported