Skip to content

Rule suggestion: flag optional chain after a non-null assertion #1397

Closed
@bradzacher

Description

@bradzacher

Preceding an optional chain with a non-null assertion is useless.

The entire point of the optional chain is that it handles the non-null case.
The non-null assertion doesn't actually change the type, and is functionally useless.

function foo(x?: { a: string }) {
    return x!?.a;
}

Thinking about it, this could potentially live as an option within no-extra-non-null-assertion, but I'm not sure if it entirely fits in there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement: new plugin ruleNew rule request for eslint-pluginhas prthere is a PR raised to close thispackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions