Redundant Optional Chaining

[redundant-optional-chaining] Some optional chaining lookups could be non-optional

This warning category is spelled [redundant-optional-chaining] by qmllint.

Redundant Optional Chaining

What happened?

Some lookups use optional chaining when it isn’t necessary. This can happen when looking up enum values or when performing a lookup on a base that cannot be null or undefined.

Why is this bad?

An optional lookup needs to perform a runtime check that a regular lookup doesn’t. These extra instructions cannot always be determined to be redundant and optimized out by the tooling. They then add an extra runtime performance cost and bloat the program unnecessarily.

Additionally, the warning may hint that the optional lookup was performed on the wrong base in the chain. See the next section for a more concrete example.

Example

To fix these warnings, replace the redundant optional lookups with non-optional ones: