Skip to content

nativeObjectExtensions

Reports extending the prototype of native JavaScript objects.

✅ This rule is included in the ts untyped presets.

Extending native JavaScript prototypes like Array.prototype or Object.prototype affects all instances of that type across the entire codebase. This can cause conflicts with other libraries that expect standard prototype behavior. Future ECMAScript versions may add methods with the same name, causing unexpected behavior when those methods are overwritten.

Array.prototype.custom = function () {
return this;
};
Object.prototype.method = 123;
String.prototype.toTitleCase = function () {
return this.charAt(0).toUpperCase() + this.slice(1);
};
Object.defineProperty(Array.prototype, "custom", {
value: function () {},
});
Object.defineProperties(Object.prototype, {
method: { value: 123 },
});

This rule is not configurable.

If you are developing a polyfill library that intentionally adds missing standard methods to native prototypes, you may need to disable this rule. Some frameworks also extend native prototypes as part of their core design, though this is increasingly rare in modern JavaScript development.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.