Skip to content

Bug: [no-inferrable-types] False negative for parameter properties #7278

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
controversial opened this issue Jul 20, 2023 · 1 comment · Fixed by #7288
Closed
4 tasks done

Bug: [no-inferrable-types] False negative for parameter properties #7278

controversial opened this issue Jul 20, 2023 · 1 comment · Fixed by #7288
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@controversial
Copy link
Contributor

controversial commented Jul 20, 2023

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.1.6&fileType=.tsx&code=MYGwhgzhAECyCeAVAphALtA3gKGtYA9gHboBOArsGgaQBS57QBmBBAXNEeQLYBGypaAF5oAZgA0jKXgD0M6ANI1JkBQA8ADsirIAJgzwbyvEAEtg0XmFIcufAcLGToczgQWklpBgEosB6AA3AlNdZlZJK1IAbgYAX2wEoA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1uYDNFpoAQwBGSWkVKoMkftA7RI4MAF8QyoA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eFYDAruuGAL4g9A&tokens=false

Repro Code

class MyTest {
  constructor(
    foo: number = 3,         // error, as expected
    public bar: number = 3,  // no error
  ) {
    void foo, bar;
  }
}

ESLint Config

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

tsconfig

{
  "compilerOptions": {
    "strict": true
  }
}

Expected Result

An error from @typescript-eslint/no-inferrable-types should appear for both parameters (both parameters include a type declaration for a trivially inferrable type).

Actual Result

An error from @typescript-eslint/no-inferrable-types appears for the standard parameter but not for the parameter written as a parameter property.

Additional Info

This issue appears with the default rule settings, i.e.

{
  ignoreParameters: false,
  ignoreProperties: false
}

This behavior might be considered expected when ignoreParameters and/or ignoreProperties is set to true (although how that behavior would be defined is a little murky, given that parameter properties are parameters and properties).

@controversial controversial 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 Jul 20, 2023
@bradzacher
Copy link
Member

This is just a gap in the rule!

https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/rules/no-inferrable-types.ts#L254-L259

@bradzacher bradzacher 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 Jul 20, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 5, 2023
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 package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
2 participants