objectPrototypeBuiltIns
Reports direct calls to Object.prototype methods on object instances.
✅ This rule is included in the tslogicalandlogicalStrictpresets.
Objects can have properties that shadow the built-in methods from Object.prototype such as hasOwnProperty, isPrototypeOf, and propertyIsEnumerable.
Additionally, objects created with Object.create(null) do not inherit from Object.prototype and will not have these methods.
Calling these methods directly on objects can lead to errors or security vulnerabilities.
Examples
Section titled “Examples”const const hasKey: any
hasKey = const object: any
object.any
hasOwnProperty("key");const const isPrototypeOf: any
isPrototypeOf = const object: any
object.any
isPrototypeOf(const other: any
other);const const isEnumerable: any
isEnumerable = const object: any
object.any
propertyIsEnumerable("prop");const const hasKey: boolean
hasKey = 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.Object.hasOwnProperty(v: PropertyKey): boolean
Determines whether an object has a property with the specified name.
hasOwnProperty.CallableFunction.call<any, [string], boolean>(this: (this: any, args_0: string) => boolean, thisArg: any, args_0: string): boolean
Calls the function with the specified object as the this value and the specified rest arguments as the arguments.
call(const object: any
object, "key");const const isPrototypeOf: boolean
isPrototypeOf = 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.Object.isPrototypeOf(v: Object): boolean
Determines whether an object exists in another object's prototype chain.
isPrototypeOf.CallableFunction.call<any, [any], boolean>(this: (this: any, args_0: any) => boolean, thisArg: any, args_0: any): boolean
Calls the function with the specified object as the this value and the specified rest arguments as the arguments.
call(const object: any
object, const other: any
other);const const isEnumerable: boolean
isEnumerable = {}.Object.propertyIsEnumerable(v: PropertyKey): boolean
Determines whether a specified property is enumerable.
propertyIsEnumerable.CallableFunction.call<any, [string], boolean>(this: (this: any, args_0: string) => boolean, thisArg: any, args_0: string): boolean
Calls the function with the specified object as the this value and the specified rest arguments as the arguments.
call(const object: any
object, "prop");Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If code only uses objects with hardcoded keys and never uses Object.create(null) or allows user-controlled object keys, this rule might not be necessary.
Alternately, if your codebase overrides these properties -which is a dangerous legacy pattern most runtimes recommend against- you might not be able to enable this rule.
Further Reading
Section titled “Further Reading”- MDN:
Object.prototype.hasOwnProperty - MDN:
Object.prototype.isPrototypeOf - MDN:
Object.prototype.propertyIsEnumerable - MDN:
Object.create
Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noPrototypeBuiltins - Deno:
no-prototype-builtins - ESLint:
no-prototype-builtins - Oxlint:
eslint/no-prototype-builtins