Skip to content

Commit

Permalink
Local check
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBarre committed Nov 17, 2020
1 parent 891693c commit 2a4e958
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/eslint-plugin/src/rules/no-unnecessary-condition.ts
Expand Up @@ -33,8 +33,6 @@ const isTruthyLiteral = (type: ts.Type): boolean =>
isBooleanLiteralType(type, true) || (isLiteralType(type) && !!type.value);

const isPossiblyFalsy = (type: ts.Type): boolean =>
isTypeUnknownType(type) ||
isTypeAnyType(type) ||
unionTypeParts(type)
// PossiblyFalsy flag includes literal values, so exclude ones that
// are definitely truthy
Expand Down Expand Up @@ -452,6 +450,10 @@ export default createRule<Options, MessageId>({
// Not a callable function
return;
}
// Predicate is always necessary if it involves `any` or `unknown`
if (returnTypes.some(t => isTypeAnyType(t) || isTypeUnknownType(t))) {
return;
}
if (!returnTypes.some(isPossiblyFalsy)) {
return context.report({
node: callback,
Expand Down

0 comments on commit 2a4e958

Please sign in to comment.