Skip to content

[no-unsafe-member-access & no-unsafe-call] false positives on values from getters #3294

Closed
@dzek69

Description

@dzek69

I'm not sure if this is a plugin or a parser problem. It does not crash but it seems more related to the parser (not giving the proper type to the rule) than actual rule. Sorry if I'm wrong.

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

Demo repo:
https://github.com/dzek69/bug-typescript-eslint-unsafe-any-getter

  • install deps (use yarn for version locks),
  • run yarn lint
{
  "rules": {
    "@typescript-eslint/no-unsafe-call": "error",
    "@typescript-eslint/no-unsafe-member-access": "error"
  },
  "parserOptions": {
    "sourceType": "module",
    "project": "./tsconfig.lint.json",
    "ecmaVersion": 9
  }
}
class Item {
    get data() {
        return {
            count: 6,
        }
    }
}

class Test {
    public get stuff() {
        return {
            list: [
                new Item(),
                new Item(),
                new Item(),
            ]
        }
    }

    public get numberStuff(): { list: Item[] } { // manually specifying the type is not helping
        return {
            list: [
                new Item(),
                new Item(),
                new Item(),
            ]
        }
    }
}

const x = new Test();

x.stuff.list.find(a => a.data.count < 3); // problem happens here

tsconfig: https://github.com/dzek69/bug-typescript-eslint-unsafe-any-getter/blob/master/tsconfig.lint.json

Expected Result

No errors should be given. Eslint should be able to get the types information from getters code

Actual Result

Two errors are happening here, both related to accessing data via getters, IDE and TypeScript don't have problems getting correct types here, Eslint does

  33:1   error  Unsafe call of an `any` typed value           @typescript-eslint/no-unsafe-call
  33:24  error  Unsafe member access .data on an `any` value  @typescript-eslint/no-unsafe-member-access

Additional Info

Versions

package version
@typescript-eslint/parser 4.22.0
TypeScript 4.2.4
ESLint 7.24.0
node 15.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    fix: user errorissue was fixed by correcting the configuration / correcting the codepackage: parserIssues related to @typescript-eslint/parser

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy