Disallow the use of optional chaining in an expression where the undefined value would raise an error.
The optional chaining operator ?. allows to access a deeply nested property, returning undefined if the property or any
intermediate object is undefined.
This usually means that we expect the expression to evaluate as undefined in some cases. Therefore, using the optional chaining
operator in a context where returning undefined is forbidden can lead to errors.
Since optional chaining represents multiple execution branches, having an error thrown in such a context can be hard to debug.
You should provide fallbacks for when the optional chaining operator is used to avoid runtime errors.
new (foo?.bar)();
const { foo } = bar?.baz;
const foo = [...bar?.baz]
new (foo?.bar ?? baz)()
const { foo } = bar?.baz || {}
const foo = bar?.baz ? [...bar.baz] : []