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.

var Array: ArrayConstructor
Array
.
ArrayConstructor.prototype: any[]
prototype
.custom = function () {
Error ts(2339) ― Property 'custom' does not exist on type 'any[]'.
return this;
};
var Object: ObjectConstructor

Provides functionality common to all JavaScript objects.

Object
.
ObjectConstructor.prototype: Object

A reference to the prototype for a class of objects.

prototype
.method = 123;
Error ts(2339) ― Property 'method' does not exist on type 'Object'.
var String: StringConstructor

Allows manipulation and formatting of text strings and determination and location of substrings within strings.

String
.
StringConstructor.prototype: String
prototype
.toTitleCase = function () {
Error ts(2339) ― Property 'toTitleCase' does not exist on type 'String'.
return this.
String.charAt(pos: number): string

Returns the character at the specified index.

@parampos The zero-based index of the desired character.

charAt
(0).
String.toUpperCase(): string

Converts all the alphabetic characters in a string to uppercase.

toUpperCase
() + this.
String.slice(start?: number, end?: number): string

Returns a section of a string.

@paramstart The index to the beginning of the specified portion of stringObj.

@paramend The index to the end of the specified portion of stringObj. The substring includes the characters up to, but not including, the character indicated by end. If this value is not specified, the substring continues to the end of stringObj.

slice
(1);
};
var Object: ObjectConstructor

Provides functionality common to all JavaScript objects.

Object
.
ObjectConstructor.defineProperty<any[]>(o: any[], p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>): any[]

Adds a property to an object, or modifies attributes of an existing property.

@paramo Object on which to add or modify the property. This can be a native JavaScript object (that is, a user-defined object or a built in object) or a DOM object.

@paramp The property name.

@paramattributes Descriptor for the property. It can be for a data property or an accessor property.

defineProperty
(
var Array: ArrayConstructor
Array
.
ArrayConstructor.prototype: any[]
prototype
, "custom", {
PropertyDescriptor.value?: any
value
: function () {},
});
var Object: ObjectConstructor

Provides functionality common to all JavaScript objects.

Object
.
ObjectConstructor.defineProperties<Object>(o: Object, properties: PropertyDescriptorMap & ThisType<any>): Object

Adds one or more properties to an object, and/or modifies attributes of existing properties.

@paramo Object on which to add or modify the properties. This can be a native JavaScript object or a DOM object.

@paramproperties JavaScript object that contains one or more descriptor objects. Each descriptor object describes a data property or an accessor property.

defineProperties
(
var Object: ObjectConstructor

Provides functionality common to all JavaScript objects.

Object
.
ObjectConstructor.prototype: Object

A reference to the prototype for a class of objects.

prototype
, {
method: {
value: number;
}
method
: {
PropertyDescriptor.value?: any
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 ❤️‍🔥 around the world by the Flint team and contributors.