Skip to main content

no-extra-non-null-assertion

Disallow extra non-null assertions.

🔧

Some problems reported by this rule are automatically fixable by the --fix ESLint command line option.

The ! non-null assertion operator in TypeScript is used to assert that a value's type does not include null or undefined. Using the operator any more than once on a single value does nothing.

eslint.config.mjs
export default tseslint.config({
rules: {
"@typescript-eslint/no-extra-non-null-assertion": "error"
}
});

Try this rule in the playground ↗

Examples

const foo: { bar: number } | null = null;
const bar = foo!!!.bar;
Open in Playground
function foo(bar: number | undefined) {
const bar: number = bar!!!;
}
Open in Playground
function foo(bar?: { n: number }) {
return bar!?.n;
}
Open in Playground

Options

This rule is not configurable.

Resources