You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a large Typescript application, and sometimes we have code like
if (shouldFireNuclearMissiles)...
while we should have written
if (shouldFireNuclearMissiles())...
(pun intended).
So forgetting to evaluate a function results in a truthy value.
I forked the tsc compiler to add basic checks for this in the conditional operator, the if-then-else, while, do and for statements, and that was very easy. We found several bugs in our large code using this forked compiler.
Would such a stricter compiler option (maybe even emitting warnings) be a sound idea?
These automatic truthy and falsy conversions are very handy, but IMHO, for large projects, the comfort they bring does not outweigh the dangers.
Most likely this idea is too much non-Javascript-like, but we're coming from sharp & strongly-typed languages, so I must make this suggestion ;-)
Thanks,
Peter
PS: I first suggested this as a TSLINT rule , but from the friendly feedback I got, it seems this belongs in the compiler instead.
The text was updated successfully, but these errors were encountered:
We have a large
Typescript
application, and sometimes we have code likeif (shouldFireNuclearMissiles)...
while we should have written
if (shouldFireNuclearMissiles())...
(pun intended).
So forgetting to evaluate a function results in a
truthy
value.I forked the
tsc
compiler to add basic checks for this in the conditional operator, theif-then-else
,while
,do
andfor
statements, and that was very easy. We found several bugs in our large code using this forked compiler.Would such a stricter compiler option (maybe even emitting warnings) be a sound idea?
These automatic
truthy
andfalsy
conversions are very handy, but IMHO, for large projects, the comfort they bring does not outweigh the dangers.Most likely this idea is too much non-
Javascript
-like, but we're coming from sharp & strongly-typed languages, so I must make this suggestion ;-)Thanks,
Peter
PS: I first suggested this as a TSLINT rule , but from the friendly feedback I got, it seems this belongs in the compiler instead.
The text was updated successfully, but these errors were encountered: