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-unnecessary-condition] Add support for non-strict mode #996
Comments
I'm unable to reproduce this against master. If you don't - then the actual type of |
I'll try to test this again on Friday. |
Having said that, with class Thing {}
class Example {
private test: Thing;
public run(): void {
if (this.test) {
// Error here.
console.log(this.test);
}
}
} ... be fine, if It's possible that I am misunderstanding something, but you'd think that code like the above would be common in a world without |
You're correct in your understanding of what happens when it's turned off. But incorrect in the understanding of how the typechecker reports types. So when we query if the type is nullable etc, the checker api just tells us that it's of type We've done it for a few rules, so we need to add it where appropriate. |
Ya, I knew that it was being reported as |
Seems inaccurate to me. Just started happening after an upgrade, I'm gonna rollback and see what happens EDIT: Actually, there's something else going on. I'm narrowing it down, and will report back. |
Confirmed, going from I even rolled back But still no luck. |
blerg... I tried hacking up Sorry... I tried to help |
@Stephen2 Are you using |
I'm not |
Turning that on makes the list of 20 silly ones go down to 3 mostly reasonable ones 🍾 Am I misunderstanding how the rules works? |
I would love to see this rule work better when strict null checks is disabled. Until that happens, I would suggest updating the documentation to indicate this limitation. A little note like "this rule requires strict-null-checks" could save people like me from scratching their heads so much :) Thanks for all of your hard work! |
The rule now errors for non-strict files. And is documented here: |
Repro
Expected Result
No error.
Actual Result
Error: Unnecessary conditional, value is always truthy.
Additional Info
n/a
Versions
@typescript-eslint/eslint-plugin
2.3.0
@typescript-eslint/parser
2.3.0
TypeScript
3.5.3
ESLint
6.1.0
node
10.16.3
npm
6.9.0
The text was updated successfully, but these errors were encountered: