Prefer Object.hasOwn() over Object.prototype.hasOwnProperty.call() for checking own properties.
✅ This rule is included in the ts stylistic and stylisticStrict presets.
Object.hasOwn() is the modern, recommended way to check if an object has a property as its own property (not inherited from the prototype chain).
It provides a safer and more convenient alternative to older patterns like Object.prototype.hasOwnProperty.call() or calling hasOwnProperty() directly on objects.
Using Object.hasOwn() avoids potential issues with objects that don’t inherit from Object.prototype, such as objects created with Object.create(null) and objects that have overridden the hasOwnProperty method.
AEconsB0hasKAE <= sp ansty="le--0:#D6DEEB;--1:#403F">53o= sp>AB0hasOwnProper5<3(sp ansty="le--0:#D9F5DD;--1:#1111">13(sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Dk1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">531"sp><);d ivclassNa="meco"><);d>);d>);d>AE53 (oAB0hasOwnProper5<3(sp ansty="le--0:#D9F5DD;--1:#1111">13(sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Dpr1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53))1"sp>< {d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">53conso sp>AB0l5<3(sp ansty="le--0:#D9F5DD;--1:#1111">13(sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4DHas proper1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">531"sp> {d><);d ivclassNa="meec-li">5);d><3}d ivclassNa="meco"><}d>}d>3}d>AEconsB0resuAE <= sp ansty="le--0:#C5E478;--1:#3B61">B0Obje= sp>A72prototyA11hasOwnProperAB0ca53(oAE<, sp ansty="le--0:#D9F5DD;--1:#1111">1, sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Dk1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">531"sp><);d ivclassNa="meco"><);d>);d>);d>AEconsB0exisAE = {<}.sp ansty="le--0:#FAF39F;--1:#1111">11hasOwnProper}.sp>AB0ca53(oAE<, sp ansty="le--0:#D9F5DD;--1:#1111">1, sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Dpr1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">531"sp><);d ivclassNa="meco"><);d>);d>);d> 44AEco61B0ha44A3F53Ob4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0ha4AE.>3F53<(obj spans="tyle--0:#C792EA;--1:#88">44(obj>1<111" spans="tyle--0:#ECC48D;--1:#98">4E4111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F111"><53) ;divclass="Name">53)><;di vdivclass="Nameexpressive-">443F53 (Ob4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0ha4AE.>3F53(o1<111" spans="tyle--0:#ECC48D;--1:#98">4E4D111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F53111"><)) {divclass="Nameec-">3F<53 spans="tyle--0:#D6DEEB;--1:#40">3F53con53 >4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B4AE.><0log spans="tyle--0:#D6DEEB;--1:#40">30log>1<111" spans="tyle--0:#ECC48D;--1:#98">4E4DHas prop111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F111">)) ><53) ;divclass="Nameec-">353)><);>);>;di><}di vdivclass="Nameexpressive-">44AEco61B0re44A3F53Ob4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0ha4AE.>3F53<(obj spans="tyle--0:#C792EA;--1:#88">44(obj>1<111" spans="tyle--0:#ECC48D;--1:#98">4E4111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F111"><53) ;divclass="Name">53)>}di><;di vdivclass="Nameexpressive-">44AEco61B0ex44A3F53Ob4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0ha4AE.>3F53<(obj spans="tyle--0:#C792EA;--1:#88">44(obj>1<111" spans="tyle--0:#ECC48D;--1:#98">4E4D111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F111"><53) ;divclass="Name">53)>;di>
This rule is not configurable.
If you need to support JavaScript environments that don’t have Object.hasOwn() (pre-ES2022), you might need to disable this rule or use a polyfill.
Object.hasOwn() is supported in Node.js 16.9.0+ and all modern browsers.
For projects with a large existing codebase using the older patterns, and projects where hasOwn and/or hasOwnProperty are overridden with custom semantics, this rule might not be applicable.