no-unsafe-optional-chaining
eslint
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"no-unsafe-optional-chaining": "error",
},
},
];Disallow use of optional chaining in contexts where the undefined value is not allowed
(obj?.foo)();
(obj?.foo).bar;
(foo?.()).bar;
(foo?.()).bar();
(obj?.foo ?? obj?.bar)();
(foo || obj?.foo)();
(obj?.foo && foo)();
(foo ? obj?.foo : bar)();
(foo, obj?.bar).baz;
(obj?.foo)`template`;
new (obj?.foo)();
[...obj?.foo];
bar(...obj?.foo);
1 in obj?.foo;
bar instanceof obj?.foo;
for (bar of obj?.foo);
// …(obj?.foo)?.();
obj?.foo();
(obj?.foo ?? bar)();
obj?.foo.bar;
obj.foo?.bar;
foo?.()?.bar;
(obj?.foo ?? bar)`template`;
new (obj?.foo ?? bar)();
const baz = {...obj?.foo};
const { bar } = obj?.foo || baz;
function* gen() {
yield obj?.foo;
yield* obj?.foo ?? [];
}
async function foo () {
const { bar } = await obj?.foo || baz;
(await obj?.foo)?.();
(await obj?.foo)?.bar;
}Examples from the ESLint documentation.
no-unsafe-optional-chaining
eslint
export default [
{
rules: {
"no-unsafe-optional-chaining": "error",
},
},
];no-unsafe-optional-chaining
eslint plugin · correctness
{
"rules": {
"no-unsafe-optional-chaining": "error"
}
}correctness/noUnsafeOptionalChaining
correctness · since 1.0.0
{
"linter": {
"rules": {
"correctness": {
"noUnsafeOptionalChaining": "error"
}
}
}
}Disallow \8 and \9 escape sequences in string literals
Disallow returning values from setters
Disallow duplicate conditions in if-else-if chains
Disallow unused private class members
Enforce for loop update clause moving the counter in the right direction
Disallow assigning to imported bindings