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.

const
const value: any
value
=
const obj: any
obj
["property"];
const obj: any
obj
["value"] = 123;
const
const name: any
name
=
const person: any
person
["firstName"];
const
const nested: any
nested
=
const data: any
data
["items"]["first"];
class
class Container
Container
{
Container.privateProperty: number
privateProperty
= 123;
}
const
const container: Container
container
= new
constructor Container(): Container
Container
();
const container: Container
container
["privateProperty"] = 123;

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

Type: boolean Default: false

// eslint ts/propertyAccessNotation: ["error", { allowIndexSignaturePropertyAccess: true }]
interface
interface Config
Config
{
[
key: string
key
: string]: string;
}
const
const config: Config
config
:
interface Config
Config
= {};
// ✅ OK with option enabled
const
const value: string
value
=
const config: Config
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.

Made with ❤️‍🔥 around the world by the Flint team and contributors.