8000 Bug: [no-inferrable-types] False negatives on auto-accessors · Issue #10763 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

Bug: [no-inferrable-types] False negatives on auto-accessors #10763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks done
yeonjuan opened this issue Feb 3, 2025 · 2 comments · Fixed by #10780
Closed
4 tasks done

Bug: [no-inferrable-types] False negatives on auto-accessors #10763

yeonjuan opened this issue Feb 3, 2025 · 2 comments · Fixed by #10780
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@yeonjuan
Copy link
Contributor
yeonjuan commented Feb 3, 2025

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.7.2&fileType=.ts&code=FAYwNghgzlAEBiB7RsDexawA4CdFagC5YA7AVwFsAjAUx1gF5YBWAbg1ghBBpkXq48%2BOAAp4CxctTqMW7AL5A&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1uYDNFpoAQwBGSWkVKoMkftA7RI4MAF8QyoA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

class Foo {
  props: number = 5; // Error (ok)
  accessor accessorProps: number = 5; // No Error (false negative)
}

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
     "@typescript-eslint/no-inferrable-types": "error"
  },
};

tsconfig

{
  "compilerOptions": {
    // ...
  }
}

Expected Result

class Foo {
  props: number = 5; // Error
  accessor accessorProps: number = 5; // Error
}

Actual Result

class Foo {
  props: number = 5; // Error
  accessor accessorProps: number = 5; // No Error
}

Additional Info

No response

@yeonjuan yeonjuan added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Feb 3, 2025
@ronami
< 8000 svg aria-label="Show options" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-kebab-horizontal"> Copy link
Member
ronami commented Feb 3, 2025

This seems like a bug to me, as the type remains the same with or without the annotation (playground link). I think this is a pretty straightforward fix.

@ronami ronami added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Feb 3, 2025
@ronami
Copy link
Member
ronami commented Feb 4, 2025

I was thinking about this some more: I think that missing accessor handling seems pretty common because it's a different AST node rather than an attribute (like readonly). I did a quick search and I think I found six additional bugs with six different rules:

I'll open an issue for each of these 🙃

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
0