Closed
Description
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 |