1 min read 42 words Updated Sep 24, 2026 Created Sep 24, 2026

Modifying existing classes or instances at runtime

// Monkey patching Array prototype
interface Array {
last(): T | undefined;
}

Array.prototype.last = function () {
return this[this.length - 1];
};

// Usage
const numbers = [1, 2, 3];
console.log(numbers.last()); // Output: 3