Skip to content

propertyAccessNotation

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.

AEconsB0valAE <= sp ansty="le--0:#D6DEEB;--1:#403F">53ob1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dproper1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<];d ivclassNa="meec-li">d53ob1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dval1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<] sp ansty="le--0:#C792EA;--1:#8844">A5<3 sp ansty="le--0:#F78C6C;--1:#AA09">821<23sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">dAEconsB0naAE <= sp ansty="le--0:#D6DEEB;--1:#403F">53perso1<1"sp ansty="le--0:#ECC48D;--1:#984E">4DfirstNa1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<];d ivclassNa="meec-li">dAEconsB0nestAE <= sp ansty="le--0:#D6DEEB;--1:#403F">53dat1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dite1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<][sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dfir1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<];d ivclassNa="meco"><];d>AEcla5<3 sp ansty="le--0:#FFCB8B;--1:#1111">11Contain53< {d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">53privatePropertA5<3 sp ansty="le--0:#F78C6C;--1:#AA09">821<23sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">5<3}d ivclassNa="meec-li">dAEconsB0containAE <= sp ansty="le--0:#7FDBCA;--1:#096E">72nAB0Contain53(<);d ivclassNa="meec-li">53containe1<1"sp ansty="le--0:#ECC48D;--1:#984E">4DprivateProper1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<] sp ansty="le--0:#C792EA;--1:#8844">A5<3 sp ansty="le--0:#F78C6C;--1:#AA09">821<23sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><3;d>
44AEco61B0v44A3F5<3obj spans="tyle--0:#C792EA;--1:#88">4<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72prop3c3F5<3obj spans="tyle--0:#C792EA;--1:#88">4<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72v34<4AE= spans="tyle--0:#D6DEEB;--1:#40">3098<2123 spans="tyle--0:#D6DEEB;--1:#40">3c44AEco61B044A3F53pe4<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72first3c44AEco61B0ne44A3F534<4AE. spans="tyle--0:#FAF39F;--1:#11">1111i4<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72f3<;di vdivclass="Nameexpressive-">44AEc31111Conta3F<53 {divclass="Nameec-">de44AEpri3F53 privatePrope4<4AE= spans="tyle--0:#D6DEEB;--1:#40">3098<2123 spans="tyle--0:#D6DEEB;--1:#40">33c44AEco61B0conta44A6E7<2new spans="tyle--0:#C792EA;--1:#88">4<4AE spans="tyle--0:#82AAFF;--1:#3B">61B0Conta3F5<3() ;divclass="Nameec-">c6376// TypeScript allows private properties to be accessed with qu3F53contai1<111" spans="tyle--0:#ECC48D;--1:#98">4E4DprivateProp1<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53] spans="tyle--0:#C792EA;--1:#88">4<4AE= spans="tyle--0:#D6DEEB;--1:#40">3098<2123 spans="tyle--0:#D6DEEB;--1:#40">3<123><;di vdivclass="Nameexpressive-">6376// Bracket notation is allowed for non-identifier 44AEco61B0v44A3F531<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dkey with sp1<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53] ;divclass="Nameec-">c44AEco61B0da44A3F531<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dkey-with-da1<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53] ;divclass="Nameec-">c6376// Bracket notation is allowed for reserved w44AEco61B0rese44A3F531<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dc1<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53] ;divclass="Nameec-">c44AEco61B0key44A3F531<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dim1<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53] ;divclass="Nameec-">c6376// Bracket notation is allowed for computed 44AEco61B0dyn44A3F53obj[variabc44AEco61B0comp44A3F5361B0ge3F53<()] ;divclass="Name"><()]>

Whether to allow accessing properties matching an index signature with bracket notation.

Type: boolean Default: false

// eslint ts/propertyAccessNotation: ["error", { allowIndexSignaturePropertyAccess: true }]
interface Config {
[key: string]: string;
}
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.