Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[no-unnecessary-condition] ignore array index return #1798

Open
Labels
accepting prsGo ahead, send a pull request that resolves this issueenhancementNew feature or requestpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@astorije

Description

@astorije

Consider the following snippet:

constfoo=['a','b','c'];// type: string[]constbar=foo[5];// type: string, value: undefined// Passes the ruleif(foo[5]){console.log(foo[5]);}// Fails the ruleif(bar){console.log(bar);}

Thanks to@Retsam's work on#1534, the first example passes the linter, however as the author mentions in their PR, it doesn't handle less trivial cases, such as storing the value in a variable (which is very common when you want to use the value being tested in the body of theif).

I realize that supporting this (and other advanced) cases might be a lift. In the meantime, or alternatively, any thoughts on an option to entirely ignore arrays? In the current state, I don't believe there is a way to make the second example above pass the linter without disabling the rule or getting rid of the variable.
I believe such option was mentioned in#1544, for reference.

Versions

packageversion
@typescript-eslint/eslint-plugin2.24.0
@typescript-eslint/parser2.24.0
TypeScript3.8.3
ESLint6.8.0
node12.14.0
npm6.13.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancementNew feature or requestpackage: 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


      [8]ページ先頭

      ©2009-2025 Movatter.jp