[@typescript-eslint/no-unnecessary-condition] Nullable object can still fail the linter #1897
Labels
package: eslint-plugin
Issues related to @typescript-eslint/eslint-plugin
stale
PRs or Issues that are at risk of being or have been closed due to inactivity for a prolonged period
Repro
Expected Result
Per the
@types/react
types,children
is optional:Because of this, I would expect all examples above to pass the rule.
Actual Result
For a reason I do not understand, the first example (
Foo
) fails the linter:But we know from the types that
props.children
is not always truthy.Additionally:
props.children
is always truthy,Baz
should failprops.req
is non-nullable (but''
is still falsy) butBar
doesn't fail eitherI can't seem to find another combination that makes the linter scream, unless I'm missing something.
Additional Info
Apologies if this has already been reported. I went through existing tickets, opened and closed, and didn't find something similar.
Versions
@typescript-eslint/eslint-plugin
2.27.0
@typescript-eslint/parser
2.27.0
TypeScript
3.8.3
ESLint
6.8.0
node
12.14.0
yarn
1.22.4
The text was updated successfully, but these errors were encountered: