type-safe-monkey-patching

Installation
SKILL.md

Type-Safe Approaches to Monkey Patching

Overview

Monkey patching - adding properties to built-in objects at runtime - is a JavaScript pattern that becomes problematic in TypeScript. TypeScript doesn't know about properties you've added to window, document, or DOM elements, leading to type errors. While as any is the quick fix, it sacrifices type safety entirely. There are better approaches that maintain type checking while modeling your runtime modifications.

When to Use This Skill

  • Adding global variables to window or document
  • Attaching data to DOM elements
  • Working with libraries that require global state (jQuery, D3)
  • Migrating JavaScript code that uses monkey patching
  • Storing application state on global objects

The Iron Rule

Never use (obj as any).property for monkey patching. Use interface augmentation or narrower type assertions that preserve type safety.

Detection

Installs
15
GitHub Stars
2
First Seen
Feb 3, 2026
type-safe-monkey-patching — marius-townhouse/effective-typescript-skills