Skip to content

[no-unnecessary-condition] False positive for nested arrays #2255

Closed
@SCG82

Description

@SCG82

Repro

{
 "extends": [
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:@typescript-eslint/recommended-requiring-type-checking"
  ],
  "rules": {
    "@typescript-eslint/no-unnecessary-condition": "warn"
  }
}
const latencies: number[][] = [];

function recordData(): void {
    if (!latencies[0])
        latencies[0] = [];
    latencies[0].push(4);
}

recordData();

Expected Result
No errors or warnings.
Actual Result

4:7  warning  Unnecessary conditional, value is always falsy  @typescript-eslint/no-unnecessary-condition

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 3.4.0
@typescript-eslint/parser 3.2.0
TypeScript 3.9.5
ESLint 7.2.0
node 12.18.1
npm 6.14.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomerspackage: 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