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: boolean
hasKey = const object: Record<string, unknown>
object.Object.hasOwnProperty(v: PropertyKey): boolean
Determines whether an object has a property with the specified name.
hasOwnProperty("key");const const isPrototypeOf: boolean
isPrototypeOf = const object: Record<string, unknown>
object.Object.isPrototypeOf(v: Object): boolean
Determines whether an object exists in another object's prototype chain.
isPrototypeOf(const other: Record<string, unknown>
other);const const isEnumerable: boolean
isEnumerable = const object: Record<string, unknown>
object.Object.propertyIsEnumerable(v: PropertyKey): boolean
Determines whether a specified property is enumerable.
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<Record<string, unknown>, [string], boolean>(this: (this: Record<string, unknown>, args_0: string) => boolean, thisArg: Record<string, unknown>, 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: Record<string, unknown>
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<Record<string, unknown>, [Record<string, unknown>], boolean>(this: (this: Record<string, unknown>, args_0: Record<string, unknown>) => boolean, thisArg: Record<string, unknown>, args_0: Record<string, unknown>): boolean
Calls the function with the specified object as the this value and the specified rest arguments as the arguments.
call(const object: Record<string, unknown>
object, const other: Record<string, unknown>
other);const const isEnumerable: boolean
isEnumerable = {}.Object.propertyIsEnumerable(v: PropertyKey): boolean
Determines whether a specified property is enumerable.
propertyIsEnumerable.CallableFunction.call<Record<string, unknown>, [string], boolean>(this: (this: Record<string, unknown>, args_0: string) => boolean, thisArg: Record<string, unknown>, 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: Record<string, unknown>
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