website/src/pages/lint/rules/noExtraNonNullAssertion.md
This rule is recommended by Rome.
Prevents the wrong usage of the non-null assertion operator (!) in TypeScript files.
The
!non-null assertion operator in TypeScript is used to assert that a value's type does not includenullorundefined. Using the operator any more than once on a single value does nothing.
Source: https://typescript-eslint.io/rules/no-extra-non-null-assertion
const bar = foo!!.bar;
function fn(bar?: { n: number }) {
return bar!?.n;
}
function fn(bar?: { n: number }) {
return ((bar!))?.();
}
const bar = foo!.bar;
obj?.string!.trim();
function fn(key: string | null) {
const obj = {};
return obj?.[key!];
}