21

The description found here is very short:

Disallows object access via string literals.

Is there any further documentation or example?

David Sherret
  • 101,669
  • 28
  • 188
  • 178

1 Answers1

25

It means you can't access objects using the bracket notation. For example:

object["property"]

This way, a simple typo will throw an error and that's why it should be avoided. Instead, it is encouraged to use strongly-typed access.

Luka Jacobowitz
  • 22,795
  • 5
  • 39
  • 57
  • 2
    Why do I need such of rule? –  Apr 18 '16 at 13:42
  • agreed, I dislike this rule becose sometimes you have to use object literals – Deunz Feb 12 '20 at 12:58
  • The reason for this rule is because there is no need to use a string literal to access a property, other than cases like `obj["prop-erty"]` (which are allowed by this rule). – Alisson Reinaldo Silva Jun 03 '20 at 05:15
  • I do like this rule because it prevents accessing a private or protected property / method when we are not supposed to. I do have to disable this rule on occasion (mostly on unit tests) inside the file itself. – Paul Sep 09 '21 at 20:17