[S1764] Using && to determine falsy/truthy in function argument

Getting bug “Identical expressions should not be used on both sides of a binary operator typescript:S1764” when analysing a function call.

Using both sides of “&&” as the same to first make sure the variable is defined (truthy), much like in conditional rendering.

          customClass && customClass

This seems like an acceptable use and could be a false-positive for the rule.

Hello Paul,

I might be missing something but it seems it would evaluate to the same thing:

  • when customClass is falsy, it will evaluate to customClass
  • when customClass is truthy, it will evaluate to customClass

In all cases c gets passed the value of customClass.

This is the case in JavaScript and TypeScript, because short-circuits evaluate to the expression value and are not casted to booleans, like in some other languages.

Is there any reason you are not calling c with customClass directly, like c(customClass)?

Hi Gabriel,

That is a great explanation, thank you. I learned something!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.