logoTUSK

Unpatch

➖ Method: Unpatch

The unpatch method is your undo button for monkey patching. It restores the original method, ensuring your code remains clean and predictable.


Syntax

unpatch(target: Object, methodName: string): void;

Parameters

PropTypeDefault
target
Object
-
methodName
string
-

Usage Example

Restoring the Original Array Prototype

restore.ts
import { unpatch } from "tusk";
 
unpatch(Array.prototype, "sum");

Reverting a Third-Party Library Patch

list.ts
import { patch, unpatch } from "tusk";
import { ListManager } from "listner";
 
patch(ListManager.prototype, "insertMultiple", function (items: any[]) {
    items.forEach((newItem) => {
        const exists = this.items.some((item) => 
            Object.keys(newItem).every((key) => item[key] === newItem[key])
        );
        if (!exists) {
            this.items.push(newItem)
        }
    })
})
 
unpatch(ListManager.prototype, "insertMultiple");

🧠 Pro Tip ╺╸ Always unpatch when you’re done to restore the original behavior and keep your codebase clean!

On this page