Reports bracket notation property access when dot notation can be used.
✅ This rule is included in the ts stylistic and stylisticStrict presets.
Dot notation (obj.property) is generally preferred over bracket notation (obj["property"]) for accessing object properties.
Dot notation is more concise and easier to read.
Bracket notation should be reserved for cases where it is necessary, such as when the property name contains special characters, is a reserved word, or is computed dynamically.
AEcons B0val AE <= sp ansty="le--0:#D6DEEB;--1:#403F">53ob= sp>1 <1"sp ansty="le--0:#ECC48D;--1:#984E">4Dproper1"sp>1 <1"sp ansty="le--0:#D6DEEB;--1:#403F">531"sp> <];d ivclassNa="meec-li">d ];d>53ob 1 <1"sp ansty="le--0:#ECC48D;--1:#984E">4Dval1"sp>1 <1"sp ansty="le--0:#D6DEEB;--1:#403F">531"sp><] sp ansty="le--0:#C792EA;--1:#8844">A] sp>5 <3 sp ansty="le--0:#F78C6C;--1:#AA09">8213 sp><23sp ansty="le--0:#D6DEEB;--1:#403F">523sp> <3;d ivclassNa="meec-li">d 3;d>AEcons B0na AE <= sp ansty="le--0:#D6DEEB;--1:#403F">53perso= sp>1 <1"sp ansty="le--0:#ECC48D;--1:#984E">4DfirstNa1"sp>1 <1"sp ansty="le--0:#D6DEEB;--1:#403F">531"sp> <];d ivclassNa="meec-li">d ];d>AEcons B0nest AE <= sp ansty="le--0:#D6DEEB;--1:#403F">53dat= sp>1 <1"sp ansty="le--0:#ECC48D;--1:#984E">4Dite1"sp>1 <1"sp ansty="le--0:#D6DEEB;--1:#403F">531"sp><][sp ansty="le--0:#D9F5DD;--1:#1111">1][sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Dfir1"sp>1 <1"sp ansty="le--0:#D6DEEB;--1:#403F">531"sp> <];d ivclassNa="meco"><];d>];d> ];d>AEcla 5 <3 sp ansty="le--0:#FFCB8B;--1:#1111">11Contain3 sp>53 < {d ivclassNa="meec-li">53 < sp ansty="le--0:#D6DEEB;--1:#403F">53privatePropert sp>A 5 <3 sp ansty="le--0:#F78C6C;--1:#AA09">8213 sp><23sp ansty="le--0:#D6DEEB;--1:#403F">523sp> {d><3;d ivclassNa="meec-li">5 3;d><3}d ivclassNa="meec-li">d 3}d>AEcons B0contain AE <= sp ansty="le--0:#7FDBCA;--1:#096E">72n= sp>A B0Contain 53( <);d ivclassNa="meec-li">53containe 1 <1"sp ansty="le--0:#ECC48D;--1:#984E">4DprivateProper1"sp>1 <1"sp ansty="le--0:#D6DEEB;--1:#403F">531"sp><] sp ansty="le--0:#C792EA;--1:#8844">A] sp>5 <3 sp ansty="le--0:#F78C6C;--1:#AA09">8213 sp><23sp ansty="le--0:#D6DEEB;--1:#403F">523sp> );d> <3;d ivclassNa="meco"><3;d>3;d> 3;d>44AEco61B0v 44A 3F5 <3obj spans="tyle--0:#C792EA;--1:#88">43obj><4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72prop4AE.>3 c 3F5<3obj spans="tyle--0:#C792EA;--1:#88">43obj><4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72v4AE.>3 4 <4AE= spans="tyle--0:#D6DEEB;--1:#40">34AE=>098 <2123 spans="tyle--0:#D6DEEB;--1:#40">32123>c 44AEco61B0 44A 3F53pe 4 <4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72first4AE.>3 c 44AEco61B0ne 44A 3F53 4 <4AE. spans="tyle--0:#FAF39F;--1:#11">1111i4AE.>4 <4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72f4AE.>3 <;di vdivclass="Nameexpressive-">44AEc3 1111Conta 3F <53 {divclass="Nameec-">de44AEpri 3F53 privatePrope 4 <4AE= spans="tyle--0:#D6DEEB;--1:#40">34AE=>098 <2123 spans="tyle--0:#D6DEEB;--1:#40">32123> 53 >3c 44AEco61B0conta 44A 6E7 <2new spans="tyle--0:#C792EA;--1:#88">42new><4AE spans="tyle--0:#82AAFF;--1:#3B">61B0Conta4AE >3F5 <3() ;divclass="Nameec-">c 3()>6376// TypeScript allows private properties to be accessed with qu3F53contai1 <111" spans="tyle--0:#ECC48D;--1:#98">4E4DprivateProp111">1 <111" spans="tyle--0:#D6DEEB;--1:#40">3F111"><53] spans="tyle--0:#C792EA;--1:#88">453] ><4AE= spans="tyle--0:#D6DEEB;--1:#40">34AE=>098 <2123 spans="tyle--0:#D6DEEB;--1:#40">32123><123>123> ;di><;di vdivclass="Nameexpressive-">6376// Bracket notation is allowed for non-identifier 44AEco61B0v 44A 3F53 1 <111" spans="tyle--0:#ECC48D;--1:#98">4E4Dkey with sp111">1 <111" spans="tyle--0:#D6DEEB;--1:#40">3F111"> <53] ;divclass="Nameec-">c 53]>44AEco61B0da 44A 3F53 1 <111" spans="tyle--0:#ECC48D;--1:#98">4E4Dkey-with-da111">1 <111" spans="tyle--0:#D6DEEB;--1:#40">3F111"> <53] ;divclass="Nameec-">c 53]>6376// Bracket notation is allowed for reserved w44AEco61B0rese 44A 3F53 1 <111" spans="tyle--0:#ECC48D;--1:#98">4E4Dc111">1 <111" spans="tyle--0:#D6DEEB;--1:#40">3F111"> <53] ;divclass="Nameec-">c 53]>44AEco61B0key 44A 3F53 1 <111" spans="tyle--0:#ECC48D;--1:#98">4E4Dim111">1 <111" spans="tyle--0:#D6DEEB;--1:#40">3F111"> <53] ;divclass="Nameec-">c 53]>6376// Bracket notation is allowed for computed 44AEco61B0dyn 44A 3F53obj[variab c 44AEco61B0comp 44A 3F53 61B0ge 3F53 <()] ;divclass="Name"><()]>()]> ()]> ;di>
Whether to allow accessing properties matching an index signature with bracket notation.
Type: boolean
Default: false
// eslint ts/propertyAccessNotation: ["error", { allowIndexSignaturePropertyAccess: true }]
const config : Config = {} ;
// ✅ OK with option enabled
const value = config[ " anyKey " ];
Disable this rule if your codebase has a convention of using bracket notation for consistency, or if you frequently access properties with names that are reserved words or contain special characters.