no-unsafe-optional-chaining
Configuration
rslint.config.ts
Rule Details
Disallows using optional chaining in contexts where the undefined value is not allowed. Optional chaining (?.) can short-circuit to undefined. When the result is used in a position where undefined causes a TypeError or unexpected behavior, this rule reports it.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
disallowArithmeticOperators
When set to true, also reports arithmetic operations on optional chaining results, which can produce NaN. Default is false.
Examples of incorrect code with { "disallowArithmeticOperators": true }: