No Optional Chaining
Ban the ?. operator so null/undefined checks are explicit because implicit chaining hides which values are expected to be nullable.
Summary
The no-optional-chaining rule reports any use of the optional chaining operator (?.), including optional property access (obj?.prop), optional element access (arr?.[0]), and optional calls (fn?.()).
The nullish coalescing operator (??) is not affected.
Why Use This Rule?
- Forces explicit null/undefined checks so the reader knows exactly which variable is nullable.
- Prevents deep chains of
?.that silently swallow missing intermediate objects. - Keeps the nullish coalescing operator (
??) available for providing defaults.
Examples
Configuration
Options
warning
ignoreFiles is an escape hatch for files where this rule genuinely does not apply. It is not intended for routine use.
| Option | Type | Default | Description |
|---|---|---|---|
ignoreFiles | string[] | [] | File patterns to skip. |
Autofix
Autofix is not available for this rule. Flagged code must be updated manually.
Troubleshooting
- Ternary replacement feels verbose — Explicit checks like
x !== undefined ? x.name : undefinedare intentionally verbose. The verbosity signals that the value is nullable and forces the reader to consider both branches. - Nullish coalescing (
??) is not flagged — Only the?.operator is banned.??is a separate operator and is permitted.