Skip to content

Bug: [no-non-null-assertion] wrong suggestion on left-hand side of an assignment #11473

@jendrikw

Description

@jendrikw

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play#ts=5.8.2&fileType=.tsx&code=CYewxgrgtgpgdgFwHQEcIwE4E8DKMA2MYCIGAFAEQCWcADhAhQJQCESAZlYQM4AEAvLzgwA7rwBiXGABkq3BGSYBuIA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1s6e4XloBDZMkTR8lDk3RQx0DtEjgwAXxAqgA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

document.querySelector("input")!.files = new FileList();

ESLint Config

{
  "rules": {
    "@typescript-eslint/no-non-null-assertion": "error"
  }
}a

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

When using @typescript-eslint/no-non-null-assertion, flagging this code is correct. But the suggested code fix is incorrect. If you apply the fix, you'll get a compiler error from tsc:

2779: The left-hand side of an assignment expression may not be an optional property access. 1:1 - 1:39

Actual Result

Error, but no suggestion.

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: 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