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.
Examples
Section titled “Examples”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 },});function customArrayMethod<T>(array: T[]): T[] { return array;}class ExtendedArray<T> extends Array<T> { custom() { return this; }}function toTitleCase(value: string) { return value.charAt(0).toUpperCase() + value.slice(1);}const arrayUtils = { custom<T>(array: T[]) { return array; },};Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
no-extend-native - Oxlint:
eslint/no-extend-native
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.