Disallow extra non-null assertions.
// code-linter.json5
{
"rules": {
"@typescript-eslint/no-extra-non-null-assertion": "error"
}
} interface BarType1 {
bar: number;
}
function getFoo(): BarType1 | null {
return null;
}
const foo: BarType1 | null = getFoo();
export const bar1: number | undefined = foo?.bar;
export function foo1(bar: number | undefined): void {
const newBar: number = bar ?? Number.MAX_VALUE;
console.info(`${newBar}`);
} interface BarType1 {
bar: number;
}
const foo1: BarType1 | null = null;
export const bar1 = foo1!!!.bar;
export function foo2(bar: number | undefined) {
const newBar: number = bar!!!;
console.info(`${newBar}`);
}
interface BarType2 {
n: number;
}
export function foo(bar?: BarType2) {
return bar!?.n;
} plugin:@typescript-eslint/all
For details about how to configure Code Linter check rules, see Code Linter.