3 ms·
I don‘t see a problem with it. !!foo and foo are in boolean logic the same, but as typescript does not allow (correctly) to use a string as a boolean value you‘
by tpetry 6y ago
I don‘t see a problem with it. !!foo and foo are in boolean logic the same, but as typescript does not allow (correctly) to use a string as a boolean value you‘re already doing !!foo for e.g. strings
- black_puppydog 6y agoYeah, I've only been working in TS for about a year, but I still find this sort of thing wrong. It's easy to get wrong since it overloads syntax (casting vs boolean ops) and is very hard to google (as many operators are).
- WorldMaker 6y agoYeah, I've started to migrate to the habit of using Boolean(expr) instead of !!expr simply because it is explicit about intent. I've seen projects with that as a tslint/eslint rule to never allow !! and instead it suggests Boolean() and I haven't quite done that in my own projects, but have considered it.