Skip to content
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

[no-inferrable-types] Boolean initialized to null tagged as inferrable #321

Closed
jp7837 opened this issue Feb 27, 2019 · 3 comments · Fixed by #442
Closed

[no-inferrable-types] Boolean initialized to null tagged as inferrable #321

jp7837 opened this issue Feb 27, 2019 · 3 comments · Fixed by #442
Labels
bug Something isn't working has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@jp7837
Copy link
Contributor

jp7837 commented Feb 27, 2019

Repro

{
  "rules": {
    "@typescript-eslint/no-inferrable-types": 2
  }
}
let myBool: boolean = null;

Expected Result
No violations

Actual Result
myBool is tagged as inferrable

Additional Info
I know strictNullTypes should be used to make this more explicit, but if it's not enabled, should null-initialized booleans be flagged as inferrable?

Versions

package version
@typescript-eslint/eslint-plugin 1.3.0
@typescript-eslint/parser 1.3.0
TypeScript 3.3.3
ESLint 5.12.0
node 8.10.0
@jp7837 jp7837 added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Feb 27, 2019
@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for maintainers to take a look labels Mar 4, 2019
@bradzacher bradzacher added working as intended Issues that are closed as they are working as intended and removed bug Something isn't working labels Apr 19, 2019
@bradzacher
Copy link
Member

Reviewing the rule, its intention and documentation - the rule is intended to help reduce unnecessary type annotations because the type is easily inferred from its literal value.

It does not validate any type annotations - it just checks:

  • is the variable's initialisation value is simple enough? and
  • does the init value's type match the type annotation?

In this case, the initialisation value (null), does not match the annotation (boolean), so the rule will not warn that the annotation is inferable, because it is not.

@jp7837
Copy link
Contributor Author

jp7837 commented Apr 19, 2019

@bradzacher sorry if the repro steps were confusing, I would also expect the rule would not warn, but the Actual Result is a no-inferrable-types violation.

@bradzacher
Copy link
Member

oh, sorrry, I misunderstood your post!
Thanks for clarifying

@bradzacher bradzacher reopened this Apr 19, 2019
@bradzacher bradzacher added bug Something isn't working has pr there is a PR raised to close this and removed working as intended Issues that are closed as they are working as intended labels Apr 25, 2019
@typescript-eslint typescript-eslint locked as resolved and limited conversation to collaborators Feb 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
2 participants