Enable @typescript-eslint/no-unnecessary-condition
to ensure no unnecessary null checks
#1686
Labels
code quality
Improvements to code quality
The problem
I recently wrote a bug where I had a function
foo()
that originally returned a nullable value, and I used it in a conditionalfoo() == null
. I switchedfoo()
to return a boolean, but forgot to update the conditional, which resulted in the conditional always evaluating tofalse
😳The solution
We'd like to introduce the
@typescript-eslint/no-unnecessary-condition
lint rule, which would have flagged an error and helped me to spot this bug.Unfortunately, when I tried to enable it, I got lots of errors. The ones I saw had to do with the following situations:
Record<string, Foo>
and then checking if it's null. Not entirely sure what to do about thesePatch
In case helpful, here's a patch to enable the lint rule
The text was updated successfully, but these errors were encountered: