1 min read 42 words Updated Oct 03, 2026 Created Oct 03, 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