13 Replies
I did this
and it works. Is there a reason why these 2 are different?
Because JavaScript ✨
The comma operator evaluates both operands then returns the one on the right. So the expression above evaluates to the same value as just
Meanwhile, this works
because you're using each
or()
as an argument here - the comma here is not the comma operator, but rather an argument delimiter.
I think the closest thing to what you were originally trying to do is to put both conditions in an array and then spread it into the and()
call, such that each element in the array end up as a different positional argument:
(wherein the comma here is an array element delimiter instead of the comma operator. I guess, succinctly, if you use a comma anywhere where it does not have some other well defined purpose, JavaScript will interpret it as the rarely-used comma operator)Ah got it! I tried putting it in an array which is what I intended to do. But it's not valid js ig (eslint: parsing error)
Interesting 👀
What's the code/full error?
I'm getting typescript: expression expected
I'm guessing because it needs a function?
Hmm... Maybe the spread within the ternary is invalid, as that's not really spreading into the args. Might need to be like
...but admittedly this all seems like something TypeScript would be mad at me for 😅
Nope that didn't work too. I'm getting must have a Symbol.iterator
Strange error... I'll play with it a bit - my TS skills aren't great and it would be nice to know what's happening here!
Me too I keep getting humbled by js. But honestly I'm find with
and
here since it's associativeI think that's probably a good choice - it'll probably end up being much more readable than whatever it takes to satisfy TS anyway 😁
Hey I'm sorry! This is working! I had to restart language server. I'll stick to using
and
which is easier to read as you saidOh no problem - I did test it myself and TS seemed happy, but I didn't want to come back with "works on my system" when
and()
was working fine. I'm glad you've got a solution in any scenario 👍👊